在C# WinForm中添加窗体大小变化和退出前确认功能,就要自行添加Resize、FormClosing事件。方法如下:
在frmMain.Designer.cs中的InitializeComponent()添加:
this.Resize += new System.EventHandler(this.frmMain_Resize);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing);
在frmMain.cs中添加:
private void frmMain_Resize(object sender, EventArgs e)
{
this.Text = "..."; //使窗体名称显示为...
}
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("你确定要退出?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes) //BoxButton按钮的Yes or No ,如果是Yes退出
e.Cancel = false;
else
e.Cancel = true;
}
在frmMain.Designer.cs中的InitializeComponent()添加:
this.Resize += new System.EventHandler(this.frmMain_Resize);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing);
在frmMain.cs中添加:
private void frmMain_Resize(object sender, EventArgs e)
{
this.Text = "..."; //使窗体名称显示为...
}
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("你确定要退出?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes) //BoxButton按钮的Yes or No ,如果是Yes退出
e.Cancel = false;
else
e.Cancel = true;
}
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。