private void fraMain_FormClosing(object sender, FormClosingEventArgs e)//窗体关闭时处理代码
        {
            e.Cancel = true; //取消窗体关闭事件 
            this.Visible = false; //隐藏主窗体 
                     }==>
private void fraMain_FormClosing(object sender, FormClosingEventArgs e)//窗体关闭时处理代码
        {
if ( e.CloseReason == CloseReason.UserClosing ){
            e.Cancel = true; //取消窗体关闭事件 
            this.Visible = false; //隐藏主窗体 
             }        }

解决方案 »

  1.   

    using System;namespace System.Windows.Forms {
        // 摘要:
        //     Specifies the reason that a form was closed.
        public enum CloseReason {
            // 摘要:
            //     The cause of the closure was not defined or could not be determined.
            None = 0,
            //
            // 摘要:
            //     The operating system is closing all applications before shutting down.
            WindowsShutDown = 1,
            //
            // 摘要:
            //     The parent form of this multiple document interface (MDI) form is closing.
            MdiFormClosing = 2,
            //
            // 摘要:
            //     The user is closing the form through the user interface (UI), for example
            //     by clicking the Close button on the form window, selecting Close from the
            //     window's control menu, or pressing ALT+F4.
            UserClosing = 3,
            //
            // 摘要:
            //     The Microsoft Windows Task Manager is closing the application.
            TaskManagerClosing = 4,
            //
            // 摘要:
            //     The owner form is closing.
            FormOwnerClosing = 5,
            //
            // 摘要:
            //     The System.Windows.Forms.Application.Exit() method of the System.Windows.Forms.Application
            //     class was invoked.
            ApplicationExitCall = 6,
        }
    }