See belows MSDN Home > MSDN Library > .NET Development > Visual Studio .NET > Developing with Visual Studio .NET > Creating Windows Applications > Windows Forms > Creating Windows Forms Visual Studio Displaying Modal and Modeless Windows Forms Forms and dialog boxes are either modal or modeless. A modal form or dialog box must be closed or hidden before you can continue working with the rest of the application. For more information about working with dialog boxes, see User Input to Dialog Boxes. Dialog boxes that display important messages should always be modal. The About dialog box in Visual Studio is an example of a modal dialog box. MessageBox is a modal form you can use. Modeless forms let you shift the focus between the form and another form without having to close the initial form. The user can continue to work elsewhere in any application while the form is displayed.Modeless forms are harder to program, because users can access them in an unpredictable order. You have to keep the state of the application consistent no matter what the user does. Often, tool windows are shown in a modeless fashion. The Find dialog box, accessible from the Edit menu in Visual Studio, is an example of a modeless dialog box. Use modeless forms to display frequently used commands or information.To display a form as a modal dialog box Call the ShowDialog method. The following example shows how to display a dialog box modally. ' Visual Basic Dim frmAbout as New Form() ' Display frmAbout as a modal dialog frmAbout.ShowDialog()// C# //Display frmAbout as a modal dialog Form frmAbout = new Form(); frmAbout.ShowDialog();// C++ Form * frmAbout = new Form(); //Display frmAbout as a modal dialog frmAbout->ShowDialog(); The Form.ShowDialog method has an optional argument, owner, that can be used to specify a parent-child relationship for a form. For example, when code in your main form shows a dialog box, you can pass Me (in Visual Basic) or this (in C#) as the owner of the dialog box to establish your main form as the owner, as the following code shows. ' Visual Basic Private Sub mnuAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAbout.Click Dim f As New Form() f.ShowDialog(Me) End Sub// C# private void mnuAbout_Click(object sender, System.EventArgs e) { Form f = new Form(); f.ShowDialog(this); }// C++ private: System::Void mnuAbout_Click(System::Object * sender, System::EventArgs * e) { Form * f = new Form(); f->ShowDialog(this); } To display a form as a modeless dialog box Call the Show method. The following example shows how to display an About dialog box in modeless format. ' Visual Basic Dim f As New Form() ' Display frmAbout as a modeless dialog. f.Show()// C# //Display frmAbout as a modeless dialog Form f= new Form(); f.Show();// C++ Form * f = new Form(); //Display f as a modeless dialog f->Show(); Note If a form is displayed as modal, the code following the ShowDialog method is not executed until the dialog box is closed. However, when a form is shown as modeless, the code following the Show method is executed immediately after the form is displayed. See Also.....Introduction to Windows Forms | Creating Windows Forms | Walkthrough: Retrieving Dialog Box Information Selectively Using Multiple Properties | Retrieving Dialog Box Information Collectively Using Objects | Dialog Boxes in Windows Forms
private void mnuAbout_Click(object sender, System.EventArgs e) { Form f = new Form(); f.ShowDialog(this); }在这段代码中,是否this就是大家说到的Parent?如果是的话大家提供的方法解决不了我说的问题。 我试过给需要模式显示的窗体(选项窗口)设置owner对象(this),但如果仍用模式显示的话仍旧屏蔽了另外一个窗口(对话窗口),除非对话窗口在选项窗口显示出来后接收一个事件作了一次hide和show操作后才不被对话窗口屏蔽;如果用非模式显示的话虽然能保证选项窗口显示在主窗口前面但屏蔽不了主窗口,也不能满足我的要求大家继续想办法啊
楼上的方法可能可行。。
MSDN Home > MSDN Library > .NET Development > Visual Studio .NET > Developing with Visual Studio .NET > Creating Windows Applications > Windows Forms > Creating Windows Forms
Visual Studio Displaying Modal and Modeless Windows Forms
Forms and dialog boxes are either modal or modeless. A modal form or dialog box must be closed or hidden before you can continue working with the rest of the application. For more information about working with dialog boxes, see User Input to Dialog Boxes. Dialog boxes that display important messages should always be modal. The About dialog box in Visual Studio is an example of a modal dialog box. MessageBox is a modal form you can use. Modeless forms let you shift the focus between the form and another form without having to close the initial form. The user can continue to work elsewhere in any application while the form is displayed.Modeless forms are harder to program, because users can access them in an unpredictable order. You have to keep the state of the application consistent no matter what the user does. Often, tool windows are shown in a modeless fashion. The Find dialog box, accessible from the Edit menu in Visual Studio, is an example of a modeless dialog box. Use modeless forms to display frequently used commands or information.To display a form as a modal dialog box Call the ShowDialog method.
The following example shows how to display a dialog box modally. ' Visual Basic
Dim frmAbout as New Form()
' Display frmAbout as a modal dialog
frmAbout.ShowDialog()// C#
//Display frmAbout as a modal dialog
Form frmAbout = new Form();
frmAbout.ShowDialog();// C++
Form * frmAbout = new Form();
//Display frmAbout as a modal dialog
frmAbout->ShowDialog();
The Form.ShowDialog method has an optional argument, owner, that can be used to specify a parent-child relationship for a form. For example, when code in your main form shows a dialog box, you can pass Me (in Visual Basic) or this (in C#) as the owner of the dialog box to establish your main form as the owner, as the following code shows. ' Visual Basic
Private Sub mnuAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
Dim f As New Form()
f.ShowDialog(Me)
End Sub// C#
private void mnuAbout_Click(object sender, System.EventArgs e)
{
Form f = new Form();
f.ShowDialog(this);
}// C++
private:
System::Void mnuAbout_Click(System::Object * sender,
System::EventArgs * e)
{
Form * f = new Form();
f->ShowDialog(this);
}
To display a form as a modeless dialog box Call the Show method.
The following example shows how to display an About dialog box in modeless format. ' Visual Basic
Dim f As New Form()
' Display frmAbout as a modeless dialog.
f.Show()// C#
//Display frmAbout as a modeless dialog
Form f= new Form();
f.Show();// C++
Form * f = new Form();
//Display f as a modeless dialog
f->Show();
Note If a form is displayed as modal, the code following the ShowDialog method is not executed until the dialog box is closed. However, when a form is shown as modeless, the code following the Show method is executed immediately after the form is displayed.
See Also.....Introduction to Windows Forms | Creating Windows Forms | Walkthrough: Retrieving Dialog Box Information Selectively Using Multiple Properties | Retrieving Dialog Box Information Collectively Using Objects | Dialog Boxes in Windows Forms
Manage Your Profile |Legal |Contact Us |MSDN Flash Newsletter
©2004 Microsoft Corporation. All rights reserved. Terms of Use |Trades |Privacy Statement
调用窗体的Show就是非模式窗体
{
Form f = new Form();
f.ShowDialog(this);
}在这段代码中,是否this就是大家说到的Parent?如果是的话大家提供的方法解决不了我说的问题。
我试过给需要模式显示的窗体(选项窗口)设置owner对象(this),但如果仍用模式显示的话仍旧屏蔽了另外一个窗口(对话窗口),除非对话窗口在选项窗口显示出来后接收一个事件作了一次hide和show操作后才不被对话窗口屏蔽;如果用非模式显示的话虽然能保证选项窗口显示在主窗口前面但屏蔽不了主窗口,也不能满足我的要求大家继续想办法啊
也许能够帮得上忙
在对话框窗口里添加如下方法
public DialogResult ShowDialogBase(Form owner)
{
bool closed = false;
owner.AddOwnedForm(this);
this.Visible = true;
owner.Enabled = false;
while(DialogResult.None == this.DialogResult)
{
Application.DoEvents();
if(!this.Visible)
{
this.DialogResult = DialogResult.Cancel;
closed = true;
break;
}
System.Threading.Thread.Sleep(0);
}
owner.Enabled = true;
if(closed) owner.BringToFront();
this.Visible = false;
owner.RemoveOwnedForm(this);
return this.DialogResult;
}调用ShowDialogBase来代替ShowDialog,
不是尽善尽美,不过对一般的应用可以作为一个选择
this.DialogResult = DialogResult.None;
否则第二次ShowDialogBase就不正常了 :)
调用窗体的Show就是非模式窗体
{
bool closed = false;
owner.AddOwnedForm(this);
this.Visible = true;
owner.Enabled = false;
while(DialogResult.None == this.DialogResult)
{
Application.DoEvents();
if(!this.Visible)
{
this.DialogResult = DialogResult.Cancel;
closed = true;
break;
}
System.Threading.Thread.Sleep(0);
}
owner.Enabled = true;
if(closed) owner.BringToFront();
this.Visible = false;
owner.RemoveOwnedForm(this);
return this.DialogResult;
}
我想问的是有没有一种机制可以让ShowDialog不屏蔽整个Application大家继续?谢谢!
System.Diagnostics.Process p =new System.Diagnostics.Process();
p.StartInfo.FileName=Application.ExecutablePath;
p.Start();
可以把程序写成一个带参数的,这样可以用StartInfo.Arguments来传递参数,使程序在不同的参数下显示不同的内容;
这样就实现了你的目的.