在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)
e.Cancel = false;
else
e.Cancel = true;
}
阅读(8874) | 评论(0) | 转发(0) |