Browse Source

添加窗体管理器

yuzhengyang 8 years ago
parent
commit
90ef0d648f

+ 2 - 6
Fork.Net/Test/Y.Test/Commons/R.cs

@@ -2,17 +2,13 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Y.Utils.DataUtils.Collections;
+using Y.Utils.WindowsUtils.FormUtils;
 
 namespace Y.Test.Commons
 {
     public static class R
     {
-        public static FormDictionaryTool FD = new FormDictionaryTool();
+        public static FormManTool Forms = new FormManTool();
 
-        public static void Test()
-        {
-            FD.Get();
-        }
     }
 }

+ 1 - 1
Fork.Net/Test/Y.Test/Program.cs

@@ -17,7 +17,7 @@ namespace Y.Test
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new TestSimpleTitle());
+            Application.Run(new MainForm());
         }
     }
 }

+ 23 - 286
Fork.Net/Test/Y.Test/Views/MainForm.Designer.cs

@@ -28,309 +28,46 @@
         /// </summary>
         private void InitializeComponent()
         {
-            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
-            this.button1 = new System.Windows.Forms.Button();
-            this.checkBox1 = new System.Windows.Forms.CheckBox();
-            this.label1 = new System.Windows.Forms.Label();
-            this.listView1 = new System.Windows.Forms.ListView();
-            this.button2 = new System.Windows.Forms.Button();
-            this.button3 = new System.Windows.Forms.Button();
-            this.button4 = new System.Windows.Forms.Button();
-            this.button5 = new System.Windows.Forms.Button();
-            this.button6 = new System.Windows.Forms.Button();
-            this.button7 = new System.Windows.Forms.Button();
-            this.button8 = new System.Windows.Forms.Button();
-            this.button9 = new System.Windows.Forms.Button();
-            this.button10 = new System.Windows.Forms.Button();
-            this.button11 = new System.Windows.Forms.Button();
-            this.button12 = new System.Windows.Forms.Button();
-            this.pictureBox1 = new System.Windows.Forms.PictureBox();
-            this.pictureBox2 = new System.Windows.Forms.PictureBox();
-            this.pictureBox3 = new System.Windows.Forms.PictureBox();
-            this.panel1 = new System.Windows.Forms.Panel();
-            this.pictureBox4 = new System.Windows.Forms.PictureBox();
-            this.pictureBox6 = new System.Windows.Forms.PictureBox();
-            this.pictureBox5 = new System.Windows.Forms.PictureBox();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
-            this.panel1.SuspendLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).BeginInit();
+            this.ChineseCalendarForm = new System.Windows.Forms.Button();
+            this.TestComputerInfoForm = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
-            // button1
+            // ChineseCalendarForm
             // 
-            this.button1.Location = new System.Drawing.Point(419, 321);
-            this.button1.Name = "button1";
-            this.button1.Size = new System.Drawing.Size(75, 23);
-            this.button1.TabIndex = 0;
-            this.button1.Text = "button1";
-            this.button1.UseVisualStyleBackColor = true;
-            this.button1.Click += new System.EventHandler(this.button1_Click);
+            this.ChineseCalendarForm.Location = new System.Drawing.Point(70, 80);
+            this.ChineseCalendarForm.Name = "ChineseCalendarForm";
+            this.ChineseCalendarForm.Size = new System.Drawing.Size(262, 23);
+            this.ChineseCalendarForm.TabIndex = 0;
+            this.ChineseCalendarForm.Text = "ChineseCalendarForm";
+            this.ChineseCalendarForm.UseVisualStyleBackColor = true;
+            this.ChineseCalendarForm.Click += new System.EventHandler(this.ChineseCalendarForm_Click);
             // 
-            // checkBox1
+            // TestComputerInfoForm
             // 
-            this.checkBox1.AutoSize = true;
-            this.checkBox1.Location = new System.Drawing.Point(416, 350);
-            this.checkBox1.Name = "checkBox1";
-            this.checkBox1.Size = new System.Drawing.Size(78, 16);
-            this.checkBox1.TabIndex = 1;
-            this.checkBox1.Text = "checkBox1";
-            this.checkBox1.UseVisualStyleBackColor = true;
-            // 
-            // label1
-            // 
-            this.label1.AutoSize = true;
-            this.label1.Location = new System.Drawing.Point(453, 369);
-            this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(41, 12);
-            this.label1.TabIndex = 2;
-            this.label1.Text = "label1";
-            // 
-            // listView1
-            // 
-            this.listView1.Location = new System.Drawing.Point(545, 62);
-            this.listView1.Name = "listView1";
-            this.listView1.Size = new System.Drawing.Size(121, 97);
-            this.listView1.TabIndex = 3;
-            this.listView1.UseCompatibleStateImageBehavior = false;
-            // 
-            // button2
-            // 
-            this.button2.Location = new System.Drawing.Point(433, 85);
-            this.button2.Name = "button2";
-            this.button2.Size = new System.Drawing.Size(75, 23);
-            this.button2.TabIndex = 4;
-            this.button2.Text = "button2";
-            this.button2.UseVisualStyleBackColor = true;
-            this.button2.Click += new System.EventHandler(this.button2_Click);
-            // 
-            // button3
-            // 
-            this.button3.Location = new System.Drawing.Point(433, 62);
-            this.button3.Name = "button3";
-            this.button3.Size = new System.Drawing.Size(75, 23);
-            this.button3.TabIndex = 5;
-            this.button3.Text = "button3";
-            this.button3.UseVisualStyleBackColor = true;
-            // 
-            // button4
-            // 
-            this.button4.Location = new System.Drawing.Point(433, 108);
-            this.button4.Name = "button4";
-            this.button4.Size = new System.Drawing.Size(75, 23);
-            this.button4.TabIndex = 6;
-            this.button4.Text = "button4";
-            this.button4.UseVisualStyleBackColor = true;
-            // 
-            // button5
-            // 
-            this.button5.Location = new System.Drawing.Point(433, 131);
-            this.button5.Name = "button5";
-            this.button5.Size = new System.Drawing.Size(75, 23);
-            this.button5.TabIndex = 7;
-            this.button5.Text = "button5";
-            this.button5.UseVisualStyleBackColor = true;
-            // 
-            // button6
-            // 
-            this.button6.Location = new System.Drawing.Point(433, 154);
-            this.button6.Name = "button6";
-            this.button6.Size = new System.Drawing.Size(75, 23);
-            this.button6.TabIndex = 8;
-            this.button6.Text = "button6";
-            this.button6.UseVisualStyleBackColor = true;
-            // 
-            // button7
-            // 
-            this.button7.Location = new System.Drawing.Point(433, 177);
-            this.button7.Name = "button7";
-            this.button7.Size = new System.Drawing.Size(75, 23);
-            this.button7.TabIndex = 9;
-            this.button7.Text = "button7";
-            this.button7.UseVisualStyleBackColor = true;
-            // 
-            // button8
-            // 
-            this.button8.Location = new System.Drawing.Point(433, 200);
-            this.button8.Name = "button8";
-            this.button8.Size = new System.Drawing.Size(75, 23);
-            this.button8.TabIndex = 10;
-            this.button8.Text = "button8";
-            this.button8.UseVisualStyleBackColor = true;
-            // 
-            // button9
-            // 
-            this.button9.Location = new System.Drawing.Point(433, 223);
-            this.button9.Name = "button9";
-            this.button9.Size = new System.Drawing.Size(75, 23);
-            this.button9.TabIndex = 11;
-            this.button9.Text = "button9";
-            this.button9.UseVisualStyleBackColor = true;
-            // 
-            // button10
-            // 
-            this.button10.Location = new System.Drawing.Point(433, 246);
-            this.button10.Name = "button10";
-            this.button10.Size = new System.Drawing.Size(75, 23);
-            this.button10.TabIndex = 12;
-            this.button10.Text = "button10";
-            this.button10.UseVisualStyleBackColor = true;
-            // 
-            // button11
-            // 
-            this.button11.Location = new System.Drawing.Point(433, 269);
-            this.button11.Name = "button11";
-            this.button11.Size = new System.Drawing.Size(75, 23);
-            this.button11.TabIndex = 13;
-            this.button11.Text = "button11";
-            this.button11.UseVisualStyleBackColor = true;
-            // 
-            // button12
-            // 
-            this.button12.Location = new System.Drawing.Point(433, 292);
-            this.button12.Name = "button12";
-            this.button12.Size = new System.Drawing.Size(75, 23);
-            this.button12.TabIndex = 14;
-            this.button12.Text = "button12";
-            this.button12.UseVisualStyleBackColor = true;
-            // 
-            // pictureBox1
-            // 
-            this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
-            this.pictureBox1.Location = new System.Drawing.Point(515, 165);
-            this.pictureBox1.Name = "pictureBox1";
-            this.pictureBox1.Size = new System.Drawing.Size(241, 92);
-            this.pictureBox1.TabIndex = 15;
-            this.pictureBox1.TabStop = false;
-            // 
-            // pictureBox2
-            // 
-            this.pictureBox2.Image = global::Y.Test.Properties.Resources.Rainbow;
-            this.pictureBox2.Location = new System.Drawing.Point(515, 263);
-            this.pictureBox2.Name = "pictureBox2";
-            this.pictureBox2.Size = new System.Drawing.Size(151, 92);
-            this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
-            this.pictureBox2.TabIndex = 16;
-            this.pictureBox2.TabStop = false;
-            // 
-            // pictureBox3
-            // 
-            this.pictureBox3.Image = global::Y.Test.Properties.Resources.Rainbow;
-            this.pictureBox3.Location = new System.Drawing.Point(515, 366);
-            this.pictureBox3.Name = "pictureBox3";
-            this.pictureBox3.Size = new System.Drawing.Size(151, 92);
-            this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
-            this.pictureBox3.TabIndex = 17;
-            this.pictureBox3.TabStop = false;
-            // 
-            // panel1
-            // 
-            this.panel1.BackColor = System.Drawing.SystemColors.Control;
-            this.panel1.Controls.Add(this.pictureBox4);
-            this.panel1.Controls.Add(this.pictureBox6);
-            this.panel1.Controls.Add(this.pictureBox5);
-            this.panel1.Location = new System.Drawing.Point(46, 31);
-            this.panel1.Name = "panel1";
-            this.panel1.Size = new System.Drawing.Size(331, 371);
-            this.panel1.TabIndex = 18;
-            // 
-            // pictureBox4
-            // 
-            this.pictureBox4.Image = global::Y.Test.Properties.Resources.Rainbow;
-            this.pictureBox4.Location = new System.Drawing.Point(13, 226);
-            this.pictureBox4.Name = "pictureBox4";
-            this.pictureBox4.Size = new System.Drawing.Size(151, 92);
-            this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
-            this.pictureBox4.TabIndex = 21;
-            this.pictureBox4.TabStop = false;
-            // 
-            // pictureBox6
-            // 
-            this.pictureBox6.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox6.Image")));
-            this.pictureBox6.Location = new System.Drawing.Point(13, 25);
-            this.pictureBox6.Name = "pictureBox6";
-            this.pictureBox6.Size = new System.Drawing.Size(241, 92);
-            this.pictureBox6.TabIndex = 19;
-            this.pictureBox6.TabStop = false;
-            // 
-            // pictureBox5
-            // 
-            this.pictureBox5.Image = global::Y.Test.Properties.Resources.Rainbow;
-            this.pictureBox5.Location = new System.Drawing.Point(13, 123);
-            this.pictureBox5.Name = "pictureBox5";
-            this.pictureBox5.Size = new System.Drawing.Size(151, 92);
-            this.pictureBox5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
-            this.pictureBox5.TabIndex = 20;
-            this.pictureBox5.TabStop = false;
+            this.TestComputerInfoForm.Location = new System.Drawing.Point(70, 149);
+            this.TestComputerInfoForm.Name = "TestComputerInfoForm";
+            this.TestComputerInfoForm.Size = new System.Drawing.Size(262, 23);
+            this.TestComputerInfoForm.TabIndex = 1;
+            this.TestComputerInfoForm.Text = "TestComputerInfoForm";
+            this.TestComputerInfoForm.UseVisualStyleBackColor = true;
+            this.TestComputerInfoForm.Click += new System.EventHandler(this.TestComputerInfoForm_Click);
             // 
             // MainForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
-            this.ClientSize = new System.Drawing.Size(27, 25);
-            this.Controls.Add(this.panel1);
-            this.Controls.Add(this.pictureBox3);
-            this.Controls.Add(this.pictureBox2);
-            this.Controls.Add(this.pictureBox1);
-            this.Controls.Add(this.button12);
-            this.Controls.Add(this.button11);
-            this.Controls.Add(this.button10);
-            this.Controls.Add(this.button9);
-            this.Controls.Add(this.button8);
-            this.Controls.Add(this.button7);
-            this.Controls.Add(this.button6);
-            this.Controls.Add(this.button5);
-            this.Controls.Add(this.button4);
-            this.Controls.Add(this.button3);
-            this.Controls.Add(this.button2);
-            this.Controls.Add(this.listView1);
-            this.Controls.Add(this.label1);
-            this.Controls.Add(this.checkBox1);
-            this.Controls.Add(this.button1);
-            this.DoubleBuffered = true;
+            this.ClientSize = new System.Drawing.Size(564, 427);
+            this.Controls.Add(this.TestComputerInfoForm);
+            this.Controls.Add(this.ChineseCalendarForm);
             this.Name = "MainForm";
-            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "MainForm";
-            this.Load += new System.EventHandler(this.MainForm_Load);
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
-            this.panel1.ResumeLayout(false);
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox6)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit();
             this.ResumeLayout(false);
-            this.PerformLayout();
 
         }
 
         #endregion
 
-        private System.Windows.Forms.Button button1;
-        private System.Windows.Forms.CheckBox checkBox1;
-        private System.Windows.Forms.Label label1;
-        private System.Windows.Forms.ListView listView1;
-        private System.Windows.Forms.Button button2;
-        private System.Windows.Forms.Button button3;
-        private System.Windows.Forms.Button button4;
-        private System.Windows.Forms.Button button5;
-        private System.Windows.Forms.Button button6;
-        private System.Windows.Forms.Button button7;
-        private System.Windows.Forms.Button button8;
-        private System.Windows.Forms.Button button9;
-        private System.Windows.Forms.Button button10;
-        private System.Windows.Forms.Button button11;
-        private System.Windows.Forms.Button button12;
-        private System.Windows.Forms.PictureBox pictureBox1;
-        private System.Windows.Forms.PictureBox pictureBox2;
-        private System.Windows.Forms.PictureBox pictureBox3;
-        private System.Windows.Forms.Panel panel1;
-        private System.Windows.Forms.PictureBox pictureBox4;
-        private System.Windows.Forms.PictureBox pictureBox6;
-        private System.Windows.Forms.PictureBox pictureBox5;
+        private System.Windows.Forms.Button ChineseCalendarForm;
+        private System.Windows.Forms.Button TestComputerInfoForm;
     }
 }

+ 6 - 21
Fork.Net/Test/Y.Test/Views/MainForm.cs

@@ -5,41 +5,26 @@ using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Forms;
-using Y.Skin.YoForm.Irregular;
-using Y.Skin.YoForm.Toast;
+using Y.Test.Commons;
 
 namespace Y.Test.Views
 {
-    public partial class MainForm : IrregularForm
+    public partial class MainForm : Form
     {
         public MainForm()
         {
             InitializeComponent();
         }
 
-        private void button2_Click(object sender, EventArgs e)
+        private void ChineseCalendarForm_Click(object sender, EventArgs e)
         {
-            Close();
+            R.Forms.Get<ChineseCalendarForm>().Show();
         }
 
-        private void MainForm_Load(object sender, EventArgs e)
+        private void TestComputerInfoForm_Click(object sender, EventArgs e)
         {
-
-        }
-
-        ToastForm _ToastForm = null;
-        public void Toast(string s = "")
-        {
-            if (_ToastForm == null || _ToastForm.IsDisposed)
-                _ToastForm = new ToastForm(this);
-
-            _ToastForm.Toast(s);
-        }
-        private void button1_Click(object sender, EventArgs e)
-        {
-            Toast("");
+            R.Forms.Get<TestComputerInfoForm>().Show();
         }
     }
 }

File diff suppressed because it is too large
+ 0 - 20593
Fork.Net/Test/Y.Test/Views/MainForm.resx


+ 0 - 47
Fork.Net/Y.Utils/DataUtils/Collections/FormDictionaryTool.cs

@@ -1,47 +0,0 @@
-//************************************************************************
-//      https://github.com/yuzhengyang
-//      author:     yuzhengyang
-//      date:       2017.7.31 - 2017.7.31
-//      desc:       Form唯一字典工具
-//      Copyright (c) yuzhengyang. All rights reserved.
-//************************************************************************
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows.Forms;
-
-namespace Y.Utils.DataUtils.Collections
-{
-    /// <summary>
-    /// Form唯一字典工具
-    /// </summary>
-    public class FormDictionaryTool
-    {
-        protected ConcurrentDictionary<Type, Form> dictionary = new ConcurrentDictionary<Type, Form>();
-
-        public T Get<T>() where T : Form
-        {
-            if (dictionary.ContainsKey(typeof(T)))
-            {
-                Form value;
-                if (dictionary.TryGetValue(typeof(T), out value))
-                {
-                    if (value != null && !value.IsDisposed)
-                    {
-                        return (T)value;
-                    }
-                }
-            }
-
-            T form = default(T);
-            if (dictionary.TryAdd(typeof(T), form))
-            {
-                return form;
-            }
-
-            return null;
-        }
-    }
-}

+ 65 - 0
Fork.Net/Y.Utils/WindowsUtils/FormUtils/FormManTool.cs

@@ -0,0 +1,65 @@
+//************************************************************************
+//      https://github.com/yuzhengyang
+//      author:     yuzhengyang
+//      date:       2017.7.31 - 2017.7.31
+//      desc:       窗体管理器
+//      Copyright (c) yuzhengyang. All rights reserved.
+//************************************************************************
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Y.Utils.WindowsUtils.FormUtils
+{
+    /// <summary>
+    /// 窗体管理器
+    /// </summary>
+    public class FormManTool
+    {
+        protected ConcurrentDictionary<Type, Form> UniqueForms = new ConcurrentDictionary<Type, Form>();
+
+        public List<Form> AllForms { get { return _AllForms; } }
+        private List<Form> _AllForms = new List<Form>();
+
+        /// <summary>
+        /// 获取窗体对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <returns></returns>
+        public T Get<T>() where T : Form, new()
+        {
+            if (UniqueForms.ContainsKey(typeof(T)))
+            {
+                // 字典中有该窗体,则读取窗体对象
+                Form value;
+                if (UniqueForms.TryGetValue(typeof(T), out value))
+                {
+                    if (value != null && !value.IsDisposed)
+                    {
+                        // 窗体对象可用(不为空、没释放),反馈窗体对象
+                        return (T)value;
+                    }
+                    else
+                    {
+                        // 窗体对象不可用,从字典中移除窗体对象
+                        Form temp;
+                        UniqueForms.TryRemove(typeof(T), out temp);
+                    }
+                }
+            }
+
+            // 未能返回正确的窗体,则创建新窗体(使用默认new方法)
+            T form = new T();
+            if (UniqueForms.TryAdd(typeof(T), form))
+            {
+                // 添加到字典成功后,返回当前窗体对象
+                _AllForms.Add(form);
+                return form;
+            }
+            return null;
+        }
+    }
+}

+ 1 - 1
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -52,7 +52,6 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AppUtils\AppUnique.cs" />
-    <Compile Include="DataUtils\Collections\FormDictionaryTool.cs" />
     <Compile Include="DataUtils\RandomUtils\RandomTool.cs" />
     <Compile Include="DataUtils\StringUtils\NumberStringTool.cs" />
     <Compile Include="DelegateUtils\ProgressDelegate.cs" />
@@ -94,6 +93,7 @@
     <Compile Include="TaskServiceUtils\TestTaskService.cs" />
     <Compile Include="WindowsUtils\APIUtils\FormStyleAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\PermissionAPI.cs" />
+    <Compile Include="WindowsUtils\FormUtils\FormManTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\ClipboardTool.cs" />
     <Compile Include="DataUtils\EncryptUtils\AesTool.cs" />
     <Compile Include="DataUtils\EncryptUtils\DesTool.cs" />