-
Mar 5th, 2008, 05:13 AM
#1
Thread Starter
Fanatic Member
Help with showing Window Form
-
Mar 5th, 2008, 07:11 AM
#2
Re: Help with showing Window Form
Thats because the code is running on a single thread, the thread that handles all the painting and updating for the formMsgPopUp form will be too busy executing the code in the Transmit method. You'd have to run the code in the Transmit method in a new thread OR show the second form in a new thread.
-
Mar 5th, 2008, 09:02 PM
#3
Thread Starter
Fanatic Member
Re: Help with showing Window Form
Thanks for that...but when i use the thread the form quickly disappear..Please see my code below.
Code:
System.Threading.Thread tMsg = new System.Threading.Thread(new System.Threading.ThreadStart(showMsgBox));
tMsg.Start();
System.Threading.Thread.Sleep(1000);
ownerForm.retCode = ownerForm.Transmit();
public static void showMsgBox()
{
FrmMsgPopUp FormMsgPopUp = new FrmMsgPopUp();
FormMsgPopUp.Show();
}
-
Mar 6th, 2008, 06:03 AM
#4
Re: Help with showing Window Form
Ah yes, that would be because the thread terminates once it reaches the end of showMsgBox, so the form would terminate along with its thread. Call ShowDialog instead of Show to keep the thread from terminating until the user has closed the form.
-
Mar 7th, 2008, 08:54 AM
#5
Re: Help with showing Window Form
You should be aware that displaying a form by calling ShowDialog in a background thread will not make it behave like a modal dialogue. The form is modal to the thread that owns it, so the background thread will block but the user will be able to ignore the dialogue and keep working in the main form. If that's OK then that's OK but it's something to be aware of.
-
Mar 7th, 2008, 10:50 AM
#6
Hyperactive Member
Re: Help with showing Window Form
As has been mentioned, the thread that you are running in is opening the form, doing it's stuff and then closing the form without giving any processing time over to windows to actually draw the formMsgPopUp form.
Now you could put the line
Code:
Application.DoEvents();
after the show, which would allow windows to do it's house keeping and redraw the form. But many people would burn you at the stake for using such a sledge hammer to crack a nut.
A neater solution is to simply call the Refresh event on the form after you show it, which will cause it to be redrawn.
So your code becomes:
Code:
FrmMsgPopUp formMsgPopUp = new FrmMsgPopUp();
formMsgPopUp.Show();
formMsgPopUp.Refresh();
ownerForm.retCode = ownerForm.Transmit();
formMsgPopUp.Close();
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Mar 7th, 2008, 10:54 AM
#7
Re: Help with showing Window Form
Originally Posted by SurfDemon
As has been mentioned, the thread that you are running in is opening the form, doing it's stuff and then closing the form without giving any processing time over to windows to actually draw the formMsgPopUp form.
Now you could put the line
Code:
Application.DoEvents();
after the show, which would allow windows to do it's house keeping and redraw the form. But many people would burn you at the stake for using such a sledge hammer to crack a nut.
A neater solution is to simply call the Refresh event on the form after you show it, which will cause it to be redrawn.
So your code becomes:
Code:
FrmMsgPopUp formMsgPopUp = new FrmMsgPopUp();
formMsgPopUp.Show();
formMsgPopUp.Refresh();
ownerForm.retCode = ownerForm.Transmit();
formMsgPopUp.Close();
Yes that would force the form to redraw, however if you were to click the window or in any other way interact with it, it would become "white" and unresponsive as shown in the first post on this thread.
-
Mar 7th, 2008, 10:58 AM
#8
Re: Help with showing Window Form
Basically, all UI elements should be handled by the UI thread. If you want to display a form it should be done from the UI thread. You could display the form in the UI thread and then use a BackgroundWorker in that form to do the work. The form is owned by the UI thread but it remains responsive because the work is being done in a background thread.
-
Mar 7th, 2008, 10:59 AM
#9
Hyperactive Member
Re: Help with showing Window Form
Originally Posted by Atheist
Yes that would force the form to redraw, however if you were to click the window or in any other way interact with it, it would become "white" and unresponsive as shown in the first post on this thread.
Mmmm. Unresponsive yes. But it shouldn't become white (undrawn). It will just stay there (being unresponsive). Which I think is what they are looking for.
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|