c#点关闭窗口键(在上角x)时要调用save()方法怎么写??

解决方案 »

  1.   

    /// <summary>
            /// 窗体关闭时的事件
            /// </summary>
            /// <param name="e"></param>
            /// <res>用于销毁快捷键和完全结束程序</res>
            protected override void OnFormClosed(FormClosedEventArgs e)
            {
                MyHotKey.Dispose(- 1);
                System.Diagnostics.Process.Start("http://www.hetaoos.com");
                ProjectData.EndApp();
            }
            
            /// <summary>
            /// 窗体即将关闭前的事件
            /// </summary>
            /// <param name="e"></param>
            /// <res>用于确认退出和保存设置</res>
            protected override void OnFormClosing(FormClosingEventArgs e)
            {
                if (Interaction.MsgBox("你真的决定退出?", ( MsgBoxStyle)((int)MsgBoxStyle.Question +(int) MsgBoxStyle.OkCancel), null) == MsgBoxResult.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
                SaveSet();
                base.OnFormClosing(e);
            }
            
            /// <summary>
            /// 窗体第一次显示时的事件
            /// </summary>
            /// <param name="e"></param>
            /// <res>用于读取设置</res>
            protected override void OnShown(EventArgs e)
            {
                ReadSet();
                base.OnShown(e);
            }
      

  2.   

    在FormClosing事件中直接調用save()方法就行,不需要去重寫事件
    private void FormClosing(object sender,eventArgs e)
    {
    save();
    }