开发者

Visual C# Window Behaver

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 instance开发者_高级运维d 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.


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜