|
it will work if i press f1 key
|
|
|
|
|
I am wanting to use a button on a form as a start/stop button for a piece of code. I could put the piece of code in the click function for the button, but is there a better way of achieving this? Via a object of another function? If so how would I trigger the start stop? Please give a code example.
Thanks in advance.
|
|
|
|
|
Well, my idea would be to use a variable: bool a; ... in the mouse_click event you write:
if(a == true) {function_call(var1);}
else {function_call(var2);}
i did not quite get it what you were doing, but... if that is what you were doing, sorry. in another way i don't know.
|
|
|
|
|
Thanks, but I don't think this is what I want.
I want the code that is started (with the start button) to run continuously (loop within the code) until the stop button is pressed.
Thanks
|
|
|
|
|
You may use a thread and in the start method of the thread you put your code and when clicking on the strat button you start the thread and you stop it when clicking on the stop button.
if you can provide us some code of yours we may help more.
good luck
|
|
|
|
|
Use a BackgroundWorker and set it to accept cancellation.
SkyWalker
|
|
|
|
|
Thanks BackgroundWorker looks right for the job !!!
|
|
|
|
|
Super
SkyWalker
|
|
|
|
|
hi all,
i have a question.How can i set a time limit in a thread. Example,i have a thread which will implement a action(A),what i want is the action(A) will abord or stop after 5 second even it haven complete its job.
any hits are welcome,
thanks in advance
cocoonwls
|
|
|
|
|
Maybe set the timer to run for 5000 milliseconds and then have the thread terminate? Just a quick thought
|
|
|
|
|
|
hi,
thanks..
You have gave me an idea to implement it;)
|
|
|
|
|
Have a sample.xml with ten lines. Iam looking for the 3rd line or the line with the tags <system>.
how can I read what is between a tag, for example
<system>unknown
I tried this code
******************
XmlTextReader reader = new XmlTextReader ("c:\\sample.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Text:
listBox1.Items.Add(reader.Value);
break;
*************************
but it list all of the values
thanX in advanced
|
|
|
|
|
The message supposed to read with the tags "SYSTEM"
for example "<system1>"unknown""
|
|
|
|
|
You'd need to post the XML, but, broadly, you should not read XML by counting lines, but by using XPath ( there's a clue, go and google XPath ).
The XmlDocument class is what you want to use to search Xml documents.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
use XmlDocument...
XmlDocument xd= new XmlDocument();
xd.load(@"x:\x.xml");
// then
xd.getElementsByTagName();
any thing u can do....
|
|
|
|
|
Hi there! I've an application in which I use Microsoft Office Document Imaging component to read scanned files(tiff format). Sometimes file can not be read by OCR so exception occurs I've put that block in try-catch block. Now to the real problem which does not occur always and on all the files or on all the systems. Sometimes while reading the tiff files "Object reference not set to an instance of an object" problem occurs. Bigger problem is that it does not occur in debugging mode but while testing the exe. My most of the code is inside try-catch block. So my question is can I trace error like inside a web appication(Application_onError) and trace the exact point where error occurs. Any help would be higly appreciated.
Thanks in advance.
Don't Quit
|
|
|
|
|
I am new to programing in general and I am doing my best to learn C#. In working on my current self invented project i have ran into a problem, I need to control what characters can be entered in a text box. I want to only allow the # 1-9 if that helps. thanks in advance for any suggestions.
|
|
|
|
|
This is a common question, but the solution is a little complex, at least for a beginner. The answer is to handle the KeyPress event for the control, and to check if the key is what you want, or to reject it. Setting Handled to true on the event args rejects the keypress, so the code is something like:
e.Handled = ! ( Char.IsNumeric(e.KeyChar) || Char.IsControl(e.KeyChar));
No warranty expressed or implied on the above line, it's a guess
Or you can use a masked edit control.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thank you, Makes sense however i get this message when i input the code... System.EventArgs' does not contain a definition for 'Handled' once again i am sure this would be something easily fixed by someone with moderate experience. Any help would be appreciated
|
|
|
|
|
EventArgs is a base class, the KeyPressed event gets passed KeyPressedEventArgs. I may be wrong it may be the KeyUp event that you need to handle.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
i added the EventArgs class, It didn't do anything. So i need to define "handled"
this
e.Handled = ! ( Char.IsNumeric(e.KeyChar) || Char.IsControl(e.KeyChar));
I'm terribly confused, but the good news that generally happens right before i begin to understand everything. So in this case what is "Handled" a method field or a constructor? and what do u recommend i do about defining it?
-- modified at 22:51 Friday 2nd February, 2007
Ok never mind i need to place this code inside a method thats tied to an event but the same problem still exists and im not all that sure of how to write that method.
|
|
|
|
|
You should use the KeyPress event; the KeyPressEventArgs has a "Handled" member
that you can set true for characters (not arbitrary keys) that you want to refuse.
Luc Pattyn
|
|
|
|
|
HAndled is a property on the KeyPressedEventArgs object, which is passed into an event handler for the key press event. If you get click on your textbox int he designer, click the lightning on the properties window, go down to 'KeyPress' and type in 'OnKeyPress', you'll get the method that needs the above code.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
almost works but i get this message
c:\Visual C# Step by Step\Chapter 1\Suduko1.1\Form1.cs(3223): 'char' does not contain a definition for 'IsNumeric'
any suggestions
|
|
|
|