User Control Closing Event

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;

            }

        }

    }

}

posted on 2011-06-27 15:25  武胜-阿伟  阅读(550)  评论(0编辑  收藏  举报