Showing and manipulating a window form
-
I want to open a window form by a method like that:
frmForm frm_Form = new frmForm();
frm_Form.Show();
//here should be sth. manipulated
frm_Form.Close();I've marked some window objects (text boxes) public, so I can call them outside.
frm_Form.lblTest.Text = "Hello World";
But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?
-
I want to open a window form by a method like that:
frmForm frm_Form = new frmForm();
frm_Form.Show();
//here should be sth. manipulated
frm_Form.Close();I've marked some window objects (text boxes) public, so I can call them outside.
frm_Form.lblTest.Text = "Hello World";
But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?
-
I want to open a window form by a method like that:
frmForm frm_Form = new frmForm();
frm_Form.Show();
//here should be sth. manipulated
frm_Form.Close();I've marked some window objects (text boxes) public, so I can call them outside.
frm_Form.lblTest.Text = "Hello World";
But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?
Hi, if all the code you've shown is running on the GUI thread (say inside a button_click handler) then none of it will have a visible effect, since the GUI actions will get queued until your code reaches its end: it is only when the GUI thread is done dealing with the button click that it can start executing the queued stuff in a hurry. Do you really want to show a form and (almost immediately) close it again?? Normally a form gets closed by an explicit user action, such as clicking an OK button or the close box. Remedy: reorganise your code, at least separate the Form.Close from everything else (use another event, such as a button click, a timer tick, whatever). BTW: DO NOT include delays in handlers, don't try Thread.Sleep() inside a button click handler, it does not make any sense whatsoever. Mind you there is one dangerous hack that may or may not be useful here: include some Application.DoEvents() calls; they are bound to cause weird effects if used inappropriately though. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
hi using(frmForm frm = new frmForm()) { frmForm.ShowWindow(this); // the using block call the Close/Dispose methode // so yopu don't need to call Close() or Dispose() } regards
-
Hi, if all the code you've shown is running on the GUI thread (say inside a button_click handler) then none of it will have a visible effect, since the GUI actions will get queued until your code reaches its end: it is only when the GUI thread is done dealing with the button click that it can start executing the queued stuff in a hurry. Do you really want to show a form and (almost immediately) close it again?? Normally a form gets closed by an explicit user action, such as clicking an OK button or the close box. Remedy: reorganise your code, at least separate the Form.Close from everything else (use another event, such as a button click, a timer tick, whatever). BTW: DO NOT include delays in handlers, don't try Thread.Sleep() inside a button click handler, it does not make any sense whatsoever. Mind you there is one dangerous hack that may or may not be useful here: include some Application.DoEvents() calls; they are bound to cause weird effects if used inappropriately though. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
I want to open a window form by a method like that:
frmForm frm_Form = new frmForm();
frm_Form.Show();
//here should be sth. manipulated
frm_Form.Close();I've marked some window objects (text boxes) public, so I can call them outside.
frm_Form.lblTest.Text = "Hello World";
But I can't see any manipulation on the window, neither in real time nor in debugging mode. How can I show my Window, do some actions on it and dispose it afterwards ?
Try inserting
frm_Form.Invalidate()
when you want the form to update/refresh itself. (I wouldn't do this after every single content change, but probably after a group of updates). Invalidate() doesn't immediately update the form, but is usually sufficient. If Invalidate() doesn't update it when you expect, try calling
frm_Form.Refresh()
From my understanding, Refresh() prompts an immediate redraw of a form (although I could be mistaken). Brandon
-
Try inserting
frm_Form.Invalidate()
when you want the form to update/refresh itself. (I wouldn't do this after every single content change, but probably after a group of updates). Invalidate() doesn't immediately update the form, but is usually sufficient. If Invalidate() doesn't update it when you expect, try calling
frm_Form.Refresh()
From my understanding, Refresh() prompts an immediate redraw of a form (although I could be mistaken). Brandon
Tried Refresh() and worked :), Invalidate didn't do it :(. Form won't only be displayed correctly in debugging mode. But that's ok. The best way of practise would be if I can do a periodical refresh on the form. But use of form object in Timer section and TimerElapsedEventHandler at the same time produces an error saying refresh can't be done when form is in both sections. If the user switches away and back to the program it seems as if the app has hung up. Because it's waiting for finishing the current process.