开发者

C# WinForms - Cannot Access Main Form When Child Form Is Open

Scenario

I have a C# WinForms application with a main开发者_如何学JAVA form. I also have a button on this main form, that, when clicked, creates and displays a new form.

The problem....

...Is that I cannot click on anything on the main form when the new form is open.

The Question

How do I solve this? Is it possible to use both forms simultaneously?

Code To Launch New Form

    private void barBtnStatsMonitor_ItemClick(object sender,   DevExpress.XtraBars.ItemClickEventArgs e)
    {
        //XtraMessageBox.Show("This Feature Has Not Been Fully Implemented Yet!");

        using (StatsMonitorForm frm = new StatsMonitorForm())
        {
            if (frm.ShowDialog() == DialogResult.OK)
            {

            }
        }
    }


ShowDialog() opens a modal dialog.

Show() opens non-modal.


Try frm.Show instead of ShowDialog. ShowDialog opens the new form as a modal dialog so you cannot access the base form until you close this one.


when closing the main form its like closing the app...

so a suggestion would be, disable the main form close button when there are child forms open... and just enable it again when there are no child forms open...

or create a global variable(a bool perhaps), that when a child form is open.. its set to true... so when pressing the close button on the main form... it checks this variable if its true it prompts to save.. else it just closes...


ShowDialog() displays the form in MODAL mode which means you must close new form opened.

    private void barBtnStatsMonitor_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) 
    { 
        //XtraMessageBox.Show("This Feature Has Not Been Fully Implemented Yet!"); 

        using (StatsMonitorForm frm = new StatsMonitorForm()) 
        { 
            frm.Show();
            //do some work here to get the dialog result some other way..
        } 
    } 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜