Ejemplo n.º 1
0
            /// <summary>
            /// 退出主程序
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            /// <remarks>
            /// 这里用FormClosing事件来控制主程序的退出,而不用Dispose事件来控制,
            /// 是为了解决其子窗口在各自的FormClosing事件中只是将其进行隐藏并取消了默认的关闭操作,
            /// 所以这里在主程序最先触发的FormClosing事件中就直接执行Me.Dispose()方法,这样就可以
            /// 跳过子窗口的FormClosing事件,而直接退出主程序了。
            /// </remarks>
            public void mainForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                AmeDrawings AllDrawing = GlbApp.ExposeAllDrawings();

                if (AllDrawing.Count() > 0)
                {
                    DialogResult result = MessageBox.Show("还有图表未处理,是否要关闭所有绘图并退出程序", "tip",
                                                          MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button3);
                    if (result == DialogResult.Yes) //关闭AME主程序,同时也关闭所有的绘图程序。
                    {
                        Hide();
                        //' --- 通过新的工作线程来执行绘图程序的关闭。
                        //Dim thd As New Thread(AddressOf Me.QuitDrawingApplications)
                        //With thd
                        //    .Name = "关闭所有绘图程序"
                        //    .Start(AllDrawing)
                        //    thd.Join()
                        //End With
                        // ---
                        //通过Main Thread来执行绘图程序的关闭。
                        QuitDrawingApplications(AllDrawing);
                    } //不关闭图表,但关闭程序
                    else if (result == DialogResult.No)
                    {
                    } //图表与程序都不关闭
                    else if (result == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
                // ---------------------- 先隐藏主界面,以达到更好的UI效果。
                Hide();
                //--------------------------- 断后工作
                try
                {
                    //关闭隐藏的Excel数据库中的所有工作簿
                    foreach (Workbook wkbk in GlbApp.ExcelApplication_DB.Workbooks)
                    {
                        wkbk.Close(false);
                    }
                    GlbApp.ExcelApplication_DB.Quit();
                    //这一步非常重要哟
                    GlbApp.ExcelApplication_DB = null;
                }
                catch (Exception)
                {
                    //有可能会出现数据库文件已经被关闭的情况
                }

                //保存主程序窗口关闭时的界面位置与大小
                APPLICATION_MAINFORM with_1    = this;
                mySettings_UI        mysetting = new mySettings_UI();

                mysetting.WindowLocation = with_1.Location;
                mysetting.WindowSize     = with_1.Size;
                mysetting.WindowState    = with_1.WindowState;
                mysetting.Save();

                //---------------------------
                //这里在主程序最先触发的FormClosing事件中就直接执行Me.Dispose()方法,
                //这样就可以跳过子窗口的FormClosing事件,而直接退出主程序了。
                Dispose();
            }
Ejemplo n.º 2
0
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <remarks></remarks>
            public APPLICATION_MAINFORM()
            {
                // This call is required by the designer.
                InitializeComponent();

                //Added to support default instance behavour in C#
                if (m_uniqueInstance == null)
                {
                    m_uniqueInstance = this;
                }
                // Add any initialization after the InitializeComponent() call.
                //----------------------------
                GlbApp = new GlobalApplication();
                //为关键字段赋初始值()
                F_main_Form = this;
                //----------------------------
                MainUI_ProjectNotOpened();
                //获取与文件或文件夹路径有关的数据
                GetPath();
                //----------------------------
                //创建新窗口,窗口在创建时默认是不隐藏的。
                frmSectionView                      = new frmDrawElevation();
                frmSectionView.FormClosing         += frmSectionView.frmDrawSectionalView_FormClosing;
                frmSectionView.Disposed            += frmSectionView.frmDrawElevation_Disposed;
                frmMnt_Incline                      = new frmDrawing_Mnt_Incline();
                frmMnt_Incline.FormClosing         += frmMnt_Incline.frmDrawing_Mnt_Incline_FormClosing;
                frmMnt_Incline.Disposed            += frmMnt_Incline.frmDrawing_Mnt_Incline_Disposed;
                frmMnt_Incline.DataWorkbookChanged += frmMnt_Incline.frmDrawing_Mnt_Incline_DataWorkbookChanged;
                frmMnt_Incline.Activated           += frmMnt_Incline.frmDrawing_Mnt_Incline_Activated;
                frmMnt_Incline.Deactivate          += frmMnt_Incline.frmDrawing_Mnt_Incline_Deactivate;
                frmMnt_Others                      = new frmDrawing_Mnt_Others();
                frmMnt_Others.Load                += frmMnt_Others.frmDrawingMonitor_Load;
                frmMnt_Others.FormClosing         += frmMnt_Others.frmDrawing_Mnt_Others_FormClosing;
                frmMnt_Others.Disposed            += frmMnt_Others.frmDrawing_Mnt_Others_Disposed;
                frmMnt_Others.DataWorkbookChanged += frmMnt_Others.frmDrawing_Mnt_Incline_DataWorkbookChanged;
                frmMnt_Others.Activated           += frmMnt_Others.frmDrawing_Mnt_Incline_Activated;
                frmMnt_Others.Deactivate          += frmMnt_Others.frmDrawing_Mnt_Incline_Deactivate;
                frmRolling = new frmRolling();

                // ----------------------- 设置MDI窗体的背景
                foreach (Control C in Controls)
                {
                    if (string.Compare(C.GetType().ToString(), "System.Windows.Forms.MdiClient", true) == 0)
                    {
                        MdiClient MDIC = (MdiClient)C;
                        MDIC.BackgroundImage       = Resources.线条背景;
                        MDIC.BackgroundImageLayout = ImageLayout.Tile;
                        break;
                    }
                }
                // ----------------------- 设置主程序窗口启动时的状态
                APPLICATION_MAINFORM with_2     = this;
                mySettings_UI        mysettings = new mySettings_UI();
                FormWindowState      winState   = mysettings.WindowState;

                switch (winState)
                {
                case FormWindowState.Maximized:
                    with_2.WindowState = winState;
                    break;

                case FormWindowState.Minimized:
                    with_2.WindowState = FormWindowState.Normal;
                    break;

                case FormWindowState.Normal:
                    with_2.WindowState = winState;
                    with_2.Location    = mysettings.WindowLocation;
                    with_2.Size        = mysettings.WindowSize;
                    break;
                }
                //在新线程中进行程序的一些属性的初始值的设置
                Thread thd = new Thread(new ThreadStart(myDefaltSettings));

                thd.Name = "程序的一些属性的初始值的设置";
                thd.Start();
            }