开发者

form goes in background

I have a form, and doing showdialog on that. It is like msg box. I am doing something like

    msgBox = new MsgBox();
    if (msgBox.InvokeRequired)
    {
      msgBox.Invoke(new ShowMsg(ShowMessage));
    }
    else
    {
      ShowMess开发者_如何学运维age();
    }

in show message i am doing Show Dialog. But the form goes in background of main form some times. please help on this.


Are you using threads?

If your threads you have to invoke the parent form, not the msgbox itself.

Form frm = new Form();
if (parent.InvokeRequired)
{
    parent.Invoke(new ThreadStart(() =>
        {
            frm.ShowDialog();
        }));
}
else
{
    frm.ShowDialog();
}

If your working without threads just remove the invoke and explain a little what ShowMessage und msgbox do.


try to use

Form.BringToFront();

http://msdn.microsoft.com/de-de/library/system.windows.forms.control.bringtofront%28v=vs.80%29.aspx


What a mess in here!!

is MsgBox your custom type derived from Form class? if so, you can simply call its ShowDialog method to have it displayed modally.

If you can't, please share the content of the ShowMessage method.


How do you call ShowDialog? You have to pass the main window (or any of its children) to the ShowDialog method, so it has a proper parent window.


Not sure how your ShowMsg and ShowMessage methods look like, but try this out:

msgBox = new MsgBox();
if (msgBox.InvokeRequired)
{
  msgBox.Invoke((MethodInvoker)delegate() { ShowMessage(); });
}
else
{
  ShowMessage();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜