Browse Source

添加 BaseForm.cs

liuyuqi-dellpc 1 year ago
parent
commit
fa67988bd4

+ 3 - 0
BatteryIndicator/BatteryIndicator.csproj

@@ -66,6 +66,9 @@
   <ItemGroup>
     <Compile Include="Background\DailyNoteTask.cs" />
     <Compile Include="Background\UpdateTask.cs" />
+    <Compile Include="UI\BaseForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
     <Compile Include="Utils\PTConfig.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

+ 29 - 0
BatteryIndicator/Program.cs

@@ -1,5 +1,6 @@
 using BatteryIndicator.Views;
 using System;
+using System.Collections.Generic;
 using System.Diagnostics;
 using System.Reflection;
 using System.Runtime.InteropServices;
@@ -9,6 +10,7 @@ namespace BatteryIndicator
 {
     static class Program
     {
+        public static List<Form> formList = new List<Form>();
         /// <summary>
         /// The main entry point for the application.
         /// </summary>
@@ -63,5 +65,32 @@ namespace BatteryIndicator
             // 如果没有其他同名进程存在,则返回 null
             return null;
         }
+        /// <summary>
+        /// new a Form object
+        /// </summary>
+        /// <param name="type"></param>
+        /// <returns></returns>
+        internal static Form getInstance(Type type) {
+            Form form = null;
+            foreach(Form formItem in Program.formList)
+            {
+                if (form.GetType() == type)
+                {
+                    form = formItem;
+                    form.Activate();
+
+                }
+                else if (form == null)
+                {
+                    object obj = Activator.CreateInstance(type);
+                    if (obj is Form)
+                    {
+                        form = obj as Form;
+                        form.Show();
+                    }
+                }
+            }
+            return form;
+        }
     }
 }

+ 25 - 0
BatteryIndicator/UI/BaseForm.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Windows.Forms;
+
+namespace BatteryIndicator.UI
+{
+    /// <summary>
+    /// Form 基类
+    /// </summary>
+    public partial class BaseForm : Form
+    {
+        public BaseForm()
+        {
+            this.Load += new EventHandler(BaseForm_Load);
+            this.FormClosed += new FormClosedEventHandler(BaseForm_FormClosed);
+        }
+        public void BaseForm_Load(object sender, EventArgs e)
+        {
+            Program.formList.Add(this);
+        }
+        public void BaseForm_FormClosed(object sender, FormClosedEventArgs e)
+        {
+            Program.formList.Remove(this);
+        }
+    }
+}

+ 63 - 47
BatteryIndicator/UI/SettingForm.Designer.cs

@@ -53,10 +53,11 @@
             // label1
             // 
             this.label1.AutoSize = true;
-            this.label1.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label1.Location = new System.Drawing.Point(84, 15);
+            this.label1.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label1.Location = new System.Drawing.Point(63, 12);
+            this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(89, 20);
+            this.label1.Size = new System.Drawing.Size(72, 16);
             this.label1.TabIndex = 0;
             this.label1.Text = "字体大小";
             this.label1.Click += new System.EventHandler(this.label1_Click);
@@ -64,10 +65,11 @@
             // label2
             // 
             this.label2.AutoSize = true;
-            this.label2.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(73, 216);
+            this.label2.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label2.Location = new System.Drawing.Point(55, 173);
+            this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(109, 20);
+            this.label2.Size = new System.Drawing.Size(88, 16);
             this.label2.TabIndex = 1;
             this.label2.Text = "充电时颜色";
             this.label2.Click += new System.EventHandler(this.label2_Click);
@@ -75,10 +77,11 @@
             // label3
             // 
             this.label3.AutoSize = true;
-            this.label3.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label3.Location = new System.Drawing.Point(57, 269);
+            this.label3.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label3.Location = new System.Drawing.Point(43, 215);
+            this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(129, 20);
+            this.label3.Size = new System.Drawing.Size(104, 16);
             this.label3.TabIndex = 2;
             this.label3.Text = "低电量时颜色";
             this.label3.Click += new System.EventHandler(this.label3_Click);
@@ -86,20 +89,22 @@
             // label4
             // 
             this.label4.AutoSize = true;
-            this.label4.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label4.Location = new System.Drawing.Point(93, 163);
+            this.label4.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label4.Location = new System.Drawing.Point(70, 130);
+            this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label4.Name = "label4";
-            this.label4.Size = new System.Drawing.Size(69, 20);
+            this.label4.Size = new System.Drawing.Size(56, 16);
             this.label4.TabIndex = 3;
             this.label4.Text = "主颜色";
             this.label4.Click += new System.EventHandler(this.label4_Click);
             // 
             // textBox1
             // 
-            this.textBox1.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.textBox1.Location = new System.Drawing.Point(215, 15);
+            this.textBox1.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.textBox1.Location = new System.Drawing.Point(161, 12);
+            this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.textBox1.Name = "textBox1";
-            this.textBox1.Size = new System.Drawing.Size(47, 30);
+            this.textBox1.Size = new System.Drawing.Size(36, 25);
             this.textBox1.TabIndex = 6;
             this.textBox1.Text = "28";
             this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
@@ -109,17 +114,19 @@
             // 
             // textBox2
             // 
-            this.textBox2.Location = new System.Drawing.Point(8, 9);
+            this.textBox2.Location = new System.Drawing.Point(6, 7);
+            this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.textBox2.Name = "textBox2";
-            this.textBox2.Size = new System.Drawing.Size(38, 25);
+            this.textBox2.Size = new System.Drawing.Size(30, 21);
             this.textBox2.TabIndex = 10;
             // 
             // textBox3
             // 
-            this.textBox3.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.textBox3.Location = new System.Drawing.Point(215, 61);
+            this.textBox3.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.textBox3.Location = new System.Drawing.Point(161, 49);
+            this.textBox3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.textBox3.Name = "textBox3";
-            this.textBox3.Size = new System.Drawing.Size(47, 30);
+            this.textBox3.Size = new System.Drawing.Size(36, 25);
             this.textBox3.TabIndex = 12;
             this.textBox3.Text = "0";
             this.textBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
@@ -130,19 +137,21 @@
             // label5
             // 
             this.label5.AutoSize = true;
-            this.label5.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label5.Location = new System.Drawing.Point(84, 61);
+            this.label5.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label5.Location = new System.Drawing.Point(63, 49);
+            this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label5.Name = "label5";
-            this.label5.Size = new System.Drawing.Size(89, 20);
+            this.label5.Size = new System.Drawing.Size(72, 16);
             this.label5.TabIndex = 11;
             this.label5.Text = "水平偏移";
             // 
             // textBox4
             // 
-            this.textBox4.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.textBox4.Location = new System.Drawing.Point(215, 106);
+            this.textBox4.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.textBox4.Location = new System.Drawing.Point(161, 85);
+            this.textBox4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.textBox4.Name = "textBox4";
-            this.textBox4.Size = new System.Drawing.Size(47, 30);
+            this.textBox4.Size = new System.Drawing.Size(36, 25);
             this.textBox4.TabIndex = 14;
             this.textBox4.Text = "0";
             this.textBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
@@ -153,10 +162,11 @@
             // label6
             // 
             this.label6.AutoSize = true;
-            this.label6.Font = new System.Drawing.Font("幼圆", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label6.Location = new System.Drawing.Point(84, 106);
+            this.label6.Font = new System.Drawing.Font("YouYuan", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label6.Location = new System.Drawing.Point(63, 85);
+            this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label6.Name = "label6";
-            this.label6.Size = new System.Drawing.Size(89, 20);
+            this.label6.Size = new System.Drawing.Size(72, 16);
             this.label6.TabIndex = 13;
             this.label6.Text = "垂直偏移";
             // 
@@ -164,9 +174,10 @@
             // 
             this.pictureBox3.BackColor = System.Drawing.SystemColors.Control;
             this.pictureBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-            this.pictureBox3.Location = new System.Drawing.Point(215, 258);
+            this.pictureBox3.Location = new System.Drawing.Point(161, 206);
+            this.pictureBox3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.pictureBox3.Name = "pictureBox3";
-            this.pictureBox3.Size = new System.Drawing.Size(47, 38);
+            this.pictureBox3.Size = new System.Drawing.Size(36, 31);
             this.pictureBox3.TabIndex = 9;
             this.pictureBox3.TabStop = false;
             this.pictureBox3.Click += new System.EventHandler(this.pictureBox3_Click);
@@ -175,9 +186,10 @@
             // 
             this.pictureBox2.BackColor = System.Drawing.SystemColors.Control;
             this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-            this.pictureBox2.Location = new System.Drawing.Point(215, 210);
+            this.pictureBox2.Location = new System.Drawing.Point(161, 168);
+            this.pictureBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.pictureBox2.Name = "pictureBox2";
-            this.pictureBox2.Size = new System.Drawing.Size(47, 38);
+            this.pictureBox2.Size = new System.Drawing.Size(36, 31);
             this.pictureBox2.TabIndex = 8;
             this.pictureBox2.TabStop = false;
             this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click);
@@ -186,9 +198,10 @@
             // 
             this.pictureBox1.BackColor = System.Drawing.SystemColors.Control;
             this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-            this.pictureBox1.Location = new System.Drawing.Point(215, 152);
+            this.pictureBox1.Location = new System.Drawing.Point(161, 122);
+            this.pictureBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.pictureBox1.Name = "pictureBox1";
-            this.pictureBox1.Size = new System.Drawing.Size(47, 38);
+            this.pictureBox1.Size = new System.Drawing.Size(36, 31);
             this.pictureBox1.TabIndex = 7;
             this.pictureBox1.TabStop = false;
             this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click_1);
@@ -199,9 +212,10 @@
             this.label7.Cursor = System.Windows.Forms.Cursors.Hand;
             this.label7.Font = new System.Drawing.Font("Consolas", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
             this.label7.ForeColor = System.Drawing.Color.DarkSlateGray;
-            this.label7.Location = new System.Drawing.Point(144, 373);
+            this.label7.Location = new System.Drawing.Point(108, 298);
+            this.label7.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label7.Name = "label7";
-            this.label7.Size = new System.Drawing.Size(56, 17);
+            this.label7.Size = new System.Drawing.Size(43, 13);
             this.label7.TabIndex = 16;
             this.label7.Text = "GITHUB";
             this.label7.Click += new System.EventHandler(this.label7_Click);
@@ -209,10 +223,11 @@
             // label8
             // 
             this.label8.AutoSize = true;
-            this.label8.Font = new System.Drawing.Font("幼圆", 12F);
-            this.label8.Location = new System.Drawing.Point(33, 320);
+            this.label8.Font = new System.Drawing.Font("YouYuan", 12F);
+            this.label8.Location = new System.Drawing.Point(25, 256);
+            this.label8.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label8.Name = "label8";
-            this.label8.Size = new System.Drawing.Size(229, 20);
+            this.label8.Size = new System.Drawing.Size(184, 16);
             this.label8.TabIndex = 17;
             this.label8.Text = "电量充满时隐藏托盘图标";
             this.label8.Click += new System.EventHandler(this.label8_Click);
@@ -220,19 +235,20 @@
             // checkBox1
             // 
             this.checkBox1.AutoSize = true;
-            this.checkBox1.Location = new System.Drawing.Point(281, 323);
+            this.checkBox1.Location = new System.Drawing.Point(211, 258);
+            this.checkBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.checkBox1.Name = "checkBox1";
-            this.checkBox1.Size = new System.Drawing.Size(18, 17);
+            this.checkBox1.Size = new System.Drawing.Size(15, 14);
             this.checkBox1.TabIndex = 18;
             this.checkBox1.UseVisualStyleBackColor = true;
             this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
             // 
-            // Settings
+            // SettingForm
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.Color.White;
-            this.ClientSize = new System.Drawing.Size(336, 402);
+            this.ClientSize = new System.Drawing.Size(252, 322);
             this.Controls.Add(this.checkBox1);
             this.Controls.Add(this.label8);
             this.Controls.Add(this.label7);
@@ -251,13 +267,13 @@
             this.Controls.Add(this.label1);
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+            this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.MaximizeBox = false;
             this.MinimizeBox = false;
-            this.Name = "Settings";
+            this.Name = "SettingForm";
             this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "设置";
-            this.Load += new System.EventHandler(this.Settings_Load);
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();

+ 3 - 5
BatteryIndicator/UI/SettingForm.cs

@@ -14,7 +14,7 @@ using System.Windows.Forms;
 
 namespace BatteryIndicator.UI
 {
-    public partial class SettingForm : Form
+    public partial class SettingForm : BaseForm
     {
         public SettingForm()
         {
@@ -236,10 +236,6 @@ namespace BatteryIndicator.UI
 
         }
 
-        private void Settings_Load(object sender, EventArgs e)
-        {
-
-        }
 
         // 电池电量充满后是否自动隐藏电池图标
         private void checkBox1_CheckedChanged(object sender, EventArgs e)
@@ -264,5 +260,7 @@ namespace BatteryIndicator.UI
             }
             cfg.Update();
         }
+
+ 
     }
 }

+ 2 - 1
BatteryIndicator/UI/SettingForm.resx

@@ -117,7 +117,8 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-   <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+  <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAABILAAASCwAAAAAAAAAA
         AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0eDgANHg4ADR4OAI0eDgL9Hg4GbR4OC00eDg6NHg