User Control Closing Event
using System.Windows.Forms;
namespace UserControlClosingEvent
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
protected override void OnCreateControl()
{
base.OnCreateControl();
this.ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);
}
void ParentForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("是否关闭父窗体?", "关闭父窗体?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = true;
}
}
}
}