1

I have a form which instances a new form that I've already created using

statuswindow statwin = new statuswindow();
statwin.ShowDialog();
return statwin;

This code is in a function. The problem is when I run the function in other code the next line of code doesn't run until the newly instanced window is closed by the user, I'm guessing this is the side-effect of using ShowDialog(), is there a way to have it use the same behaver (being topmost, not being to select the other main window) while still letting the main form's code run?

Update: Although Show(); will work, I need to be able to make the window like a dialog by having it always on top of the other window and it always being the active selected window.

2 Answers 2

3

The ShowDialog method of showing a window shows it as a dialog, which is a blocking mechanism within C#/.net. If you want to simply display the window and not cause the running code to block until it is closed, you can use the window.Show() function.

In your code:

startwin.Show();

This will cause the startwin form to become visable to the user, and will fire the startwin.VisibleChanged event as well as the startwin.Load event to fire.

2
  • Not quite the answer I was looking for, but useful. Do you know of a way to make the window always on top of the other window like a dialog? Also is there a way to make the new window run in a separate thread?
    – James T
    Jan 15, 2011 at 3:16
  • 1
    Check out the documentation for thread @ msdn.microsoft.com/en-us/library/system.threading.thread.aspx that should help you get started with threads (just make a new thread which shows the window). You can make the window stay on top using the Form.BringToFront method, you may need to overload a few events to call that method when appropriate.
    – Warbum
    Jan 15, 2011 at 3:24
1

To make the new window always on top, you could set the Topmost window flag in the form properties. To make the window run in a separate thread, first spawn the thread, then create the window from that thread. There are also "application modal" and "system modal" Win32 window flags, but I don't know if those are exposed to WinForms or not -- go have a look on the form properties!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.