111,098
社区成员




public static MsgBoxResult Show(string msg, string title)
{
MainWindow msgBox =null ;
msgBox = new MainWindow();
msgBox.Title = title;
msgBox.Message = msg;
msgBox.ShowDialog();
return msgBox.BoxResult;
}
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2.Show("", "");
}
}
}
Form2
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public static void Show(string msg, string title)
{
Form2 msgBox = null;
msgBox = new Form2();
msgBox.ShowDialog();
}
}
}
public static class abc
{
public static void RegisterMessageBox(Form f)
{
f.Activated += (s, e) =>
{
MyMsgBox msg = GetMessageBoxWindow();
if (msg != null && msg.正在显示)
{
msg.Focus();
}
};
}
......................
}
}
然后在其它所有窗体的 Form_Load 方法中都调用它一次。