Prechádzať zdrojové kódy

在Shodialog之后退出主窗口:要使用Dispose才不会出现闪烁现象,而直接使用Application.Exit()会闪烁。

jianfeng1.wang 2 rokov pred
rodič
commit
65dd8d9f25

+ 14 - 12
FactoryTool/FactoryTool/LoginView.Designer.cs

@@ -29,7 +29,6 @@
         private void InitializeComponent()
         {
             this.components = new System.ComponentModel.Container();
-            this.mvvmContext1 = new DevExpress.Utils.MVVM.MVVMContext(this.components);
             this.pictureEdit1 = new DevExpress.XtraEditors.PictureEdit();
             this.labelControl1 = new DevExpress.XtraEditors.LabelControl();
             this.labelControl2 = new DevExpress.XtraEditors.LabelControl();
@@ -37,17 +36,13 @@
             this.comboBoxEdit1 = new DevExpress.XtraEditors.ComboBoxEdit();
             this.BTN_LOGIN = new DevExpress.XtraEditors.SimpleButton();
             this.BTN_CANCLE = new DevExpress.XtraEditors.SimpleButton();
-            ((System.ComponentModel.ISupportInitialize)(this.mvvmContext1)).BeginInit();
+            this.mvvmContext1 = new DevExpress.Utils.MVVM.MVVMContext(this.components);
             ((System.ComponentModel.ISupportInitialize)(this.pictureEdit1.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.textEdit1.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.comboBoxEdit1.Properties)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.mvvmContext1)).BeginInit();
             this.SuspendLayout();
             // 
-            // mvvmContext1
-            // 
-            this.mvvmContext1.ContainerControl = this;
-            this.mvvmContext1.ViewModelType = typeof(FactoryTool.LoginViewModel);
-            // 
             // pictureEdit1
             // 
             this.pictureEdit1.Dock = System.Windows.Forms.DockStyle.Top;
@@ -70,7 +65,7 @@
             // 
             // labelControl2
             // 
-            this.labelControl2.Location = new System.Drawing.Point(106, 160);
+            this.labelControl2.Location = new System.Drawing.Point(106, 163);
             this.labelControl2.Name = "labelControl2";
             this.labelControl2.Size = new System.Drawing.Size(36, 14);
             this.labelControl2.TabIndex = 2;
@@ -78,7 +73,7 @@
             // 
             // textEdit1
             // 
-            this.textEdit1.Location = new System.Drawing.Point(148, 157);
+            this.textEdit1.Location = new System.Drawing.Point(148, 160);
             this.textEdit1.Name = "textEdit1";
             this.textEdit1.Size = new System.Drawing.Size(123, 20);
             this.textEdit1.TabIndex = 3;
@@ -94,7 +89,7 @@
             // 
             // BTN_LOGIN
             // 
-            this.BTN_LOGIN.Location = new System.Drawing.Point(69, 189);
+            this.BTN_LOGIN.Location = new System.Drawing.Point(69, 191);
             this.BTN_LOGIN.Name = "BTN_LOGIN";
             this.BTN_LOGIN.Size = new System.Drawing.Size(96, 23);
             this.BTN_LOGIN.TabIndex = 5;
@@ -103,13 +98,18 @@
             // 
             // BTN_CANCLE
             // 
-            this.BTN_CANCLE.Location = new System.Drawing.Point(212, 189);
+            this.BTN_CANCLE.Location = new System.Drawing.Point(212, 191);
             this.BTN_CANCLE.Name = "BTN_CANCLE";
             this.BTN_CANCLE.Size = new System.Drawing.Size(96, 23);
             this.BTN_CANCLE.TabIndex = 6;
             this.BTN_CANCLE.Text = "取消";
             this.BTN_CANCLE.Click += new System.EventHandler(this.BTN_CANCLE_Click);
             // 
+            // mvvmContext1
+            // 
+            this.mvvmContext1.ContainerControl = this;
+            this.mvvmContext1.ViewModelType = typeof(FactoryTool.LoginViewModel);
+            // 
             // LoginView
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
@@ -122,15 +122,17 @@
             this.Controls.Add(this.labelControl2);
             this.Controls.Add(this.labelControl1);
             this.Controls.Add(this.pictureEdit1);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
             this.IconOptions.Image = global::FactoryTool.Properties.Resources.logo;
             this.MaximizeBox = false;
             this.MinimizeBox = false;
             this.Name = "LoginView";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "系统登录";
-            ((System.ComponentModel.ISupportInitialize)(this.mvvmContext1)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureEdit1.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.textEdit1.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.comboBoxEdit1.Properties)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.mvvmContext1)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 

+ 12 - 11
FactoryTool/FactoryTool/MainView.Designer.cs

@@ -30,10 +30,10 @@
         {
             this.components = new System.ComponentModel.Container();
             this.ribbonControl1 = new DevExpress.XtraBars.Ribbon.RibbonControl();
+            this.skinRibbonGalleryBarItem1 = new DevExpress.XtraBars.SkinRibbonGalleryBarItem();
             this.ribbonPage1 = new DevExpress.XtraBars.Ribbon.RibbonPage();
             this.ribbonPageGroup1 = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
             this.mvvmContext1 = new DevExpress.Utils.MVVM.MVVMContext(this.components);
-            this.skinRibbonGalleryBarItem1 = new DevExpress.XtraBars.SkinRibbonGalleryBarItem();
             ((System.ComponentModel.ISupportInitialize)(this.ribbonControl1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.mvvmContext1)).BeginInit();
             this.SuspendLayout();
@@ -55,6 +55,16 @@
             this.ribbonPage1});
             this.ribbonControl1.Size = new System.Drawing.Size(884, 160);
             // 
+            // skinRibbonGalleryBarItem1
+            // 
+            this.skinRibbonGalleryBarItem1.Caption = "skinRibbonGalleryBarItem1";
+            // 
+            // 
+            // 
+            this.skinRibbonGalleryBarItem1.Gallery.ItemClick += new DevExpress.XtraBars.Ribbon.GalleryItemClickEventHandler(this.skinRibbonGalleryBarItem1_Gallery_ItemClick);
+            this.skinRibbonGalleryBarItem1.Id = 1;
+            this.skinRibbonGalleryBarItem1.Name = "skinRibbonGalleryBarItem1";
+            // 
             // ribbonPage1
             // 
             this.ribbonPage1.Groups.AddRange(new DevExpress.XtraBars.Ribbon.RibbonPageGroup[] {
@@ -73,16 +83,6 @@
             this.mvvmContext1.ContainerControl = this;
             this.mvvmContext1.ViewModelType = typeof(FactoryTool.MainViewModel);
             // 
-            // skinRibbonGalleryBarItem1
-            // 
-            this.skinRibbonGalleryBarItem1.Caption = "skinRibbonGalleryBarItem1";
-            // 
-            // 
-            // 
-            this.skinRibbonGalleryBarItem1.Gallery.ItemClick += new DevExpress.XtraBars.Ribbon.GalleryItemClickEventHandler(this.skinRibbonGalleryBarItem1_Gallery_ItemClick);
-            this.skinRibbonGalleryBarItem1.Id = 1;
-            this.skinRibbonGalleryBarItem1.Name = "skinRibbonGalleryBarItem1";
-            // 
             // MainView
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
@@ -92,6 +92,7 @@
             this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.Name = "MainView";
             this.Ribbon = this.ribbonControl1;
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "MainView";
             this.Load += new System.EventHandler(this.MainView_Load);
             ((System.ComponentModel.ISupportInitialize)(this.ribbonControl1)).EndInit();

+ 15 - 16
FactoryTool/FactoryTool/MainView.cs

@@ -19,20 +19,13 @@ namespace FactoryTool
     {
         public MainView()
         {
-            this.Load += ucRibbon_Load;
             InitializeComponent();
             if (!mvvmContext1.IsDesignMode)
                 InitializeBindings();
         }
 
-
         string[] skinsToHide = { "Basic", "The Bezier", "Xmas 2008 Blue", "Seven Classic", "DevExpress Style", "Dark", "2010", "2007", "Sharp" };
 
-        void ucRibbon_Load(object sender, EventArgs e)
-        {
-            HideGalleryItemsByCaptions(skinRibbonGalleryBarItem1, skinsToHide);
-        }
-
         private void HideGalleryItemsByCaptions(RibbonGalleryBarItem galleryItem, string[] skinsToHide)
         {
             var allItems = galleryItem.Gallery.GetAllItems();
@@ -43,7 +36,7 @@ namespace FactoryTool
             }
         }
 
-        void InitializeBindings()
+        private void InitializeBindings()
         {
             var fluent = mvvmContext1.OfType<MainViewModel>();
         }
@@ -51,17 +44,23 @@ namespace FactoryTool
         private void MainView_Load(object sender, EventArgs e)
         {
             LoginView loginView = new LoginView();
-            if ( loginView.ShowDialog() != DialogResult.OK )
+            if (loginView.ShowDialog() != DialogResult.OK)
             {
-                Application.Exit();
+                Dispose();  // 使用Dispose时,主窗口退出不闪烁;
+                // Application.Exit(); // 直接退出进程时,主窗口会闪烁;
+                return;
             }
+            else
+            {
+                // 显示欢迎界面;
+                SplashScreenManager.ShowForm(typeof(WelcomeScreen));
+                // 展示5秒;
+                Thread.Sleep(1000);
+                // 关闭欢迎界面;
+                SplashScreenManager.CloseForm();
 
-            // 显示欢迎界面;
-            SplashScreenManager.ShowForm(typeof(WelcomeScreen));
-            // 展示5秒;
-            Thread.Sleep(1000);
-            // 关闭欢迎界面;
-            SplashScreenManager.CloseForm();
+                HideGalleryItemsByCaptions(skinRibbonGalleryBarItem1, skinsToHide);
+            }
         }
 
         private void skinRibbonGalleryBarItem1_Gallery_ItemClick(object sender, GalleryItemClickEventArgs e)