Переглянути джерело

最小化 悬浮窗显示

zhiyong 4 роки тому
батько
коміт
d9f82c4f7a

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/DiodesADT/obj
+/DllFileSoc/obj
+/DiodesADT/bin/Debug

BIN
.vs/DiodesADT/v16/.suo


+ 9 - 0
DiodesADT/DiodesADT.csproj

@@ -89,6 +89,12 @@
     <Compile Include="Form\ParmView.Designer.cs">
       <DependentUpon>ParmView.cs</DependentUpon>
     </Compile>
+    <Compile Include="FrmPaint.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="FrmPaint.Designer.cs">
+      <DependentUpon>FrmPaint.cs</DependentUpon>
+    </Compile>
     <Compile Include="Lib\LogBLL.cs" />
     <Compile Include="Lib\MessageBoxDelay.cs" />
     <Compile Include="Lib\SetDataGridViewStyle.cs" />
@@ -202,6 +208,9 @@
     <EmbeddedResource Include="Form\LoginForm.resx">
       <DependentUpon>LoginForm.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="FrmPaint.resx">
+      <DependentUpon>FrmPaint.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="MachinesControl.resx">
       <DependentUpon>MachinesControl.cs</DependentUpon>
     </EmbeddedResource>

+ 18 - 0
DiodesADT/Form/ADTForm.cs

@@ -15,6 +15,7 @@ namespace DiodesADT
 {
     public partial class ADTForm : Form
     {
+        FrmPaint fp = null;
         public ADTForm()
         {
             InitializeComponent();
@@ -88,6 +89,8 @@ namespace DiodesADT
             if (btnSender!=null)
             {
                 ChangeFormlabel(btnSender.Text);
+                if (btnSender.Text == "最小化")
+                    MinFrm();
                 if (btnSender.Text == "领料管理")
                     LoadPanelForm(new MaterialView());
                 if (btnSender.Text == "产量收集")
@@ -117,6 +120,21 @@ namespace DiodesADT
             } 
         }
 
+        private void MinFrm() 
+        {
+            this.Hide();
+            if (fp == null || fp.IsDisposed)
+            {
+                fp = new FrmPaint(this);
+                fp.Show();
+            }
+            else
+            {
+                fp.Activate();
+                fp.Show();
+            }
+        }
+
         public void ChangeFormlabel(string name) 
         {
             this.Text = $"ADTForm--[{name}]";

+ 105 - 0
DiodesADT/FrmPaint.Designer.cs

@@ -0,0 +1,105 @@
+namespace DiodesADT
+{
+    partial class FrmPaint
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.button1 = new System.Windows.Forms.Button();
+            this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // button1
+            // 
+            this.button1.Location = new System.Drawing.Point(324, 175);
+            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;
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label1.ForeColor = System.Drawing.Color.White;
+            this.label1.Location = new System.Drawing.Point(3, 29);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(101, 22);
+            this.label1.TabIndex = 1;
+            this.label1.Text = "EapForADT";
+            this.label1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.FrmPaint_MouseDoubleClick);
+            this.label1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form_Base_MouseDown);
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("微软雅黑", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label2.ForeColor = System.Drawing.Color.White;
+            this.label2.Location = new System.Drawing.Point(24, 60);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(52, 16);
+            this.label2.TabIndex = 2;
+            this.label2.Text = "双击还原";
+            this.label2.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.FrmPaint_MouseDoubleClick);
+            this.label2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form_Base_MouseDown);
+            // 
+            // FrmPaint
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.BackColor = System.Drawing.Color.DeepSkyBlue;
+            this.ClientSize = new System.Drawing.Size(100, 100);
+            this.ControlBox = false;
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.button1);
+            this.ForeColor = System.Drawing.SystemColors.ControlText;
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+            this.Name = "FrmPaint";
+            this.ShowIcon = false;
+            this.ShowInTaskbar = false;
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "FrmPaint";
+            this.TopMost = true;
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmPaint_FormClosing);
+            this.Load += new System.EventHandler(this.FrmPaint_Load);
+            this.Paint += new System.Windows.Forms.PaintEventHandler(this.FrmPaint_Paint);
+            this.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.FrmPaint_MouseDoubleClick);
+            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form_Base_MouseDown);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button button1;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Label label2;
+    }
+}

+ 99 - 0
DiodesADT/FrmPaint.cs

@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Windows.Forms;
+
+namespace DiodesADT
+{
+    public partial class FrmPaint : Form
+    {
+        [DllImport("user32.dll")]  //需添加using System.Runtime.InteropServices
+        public static extern bool ReleaseCapture();
+        [DllImport("user32.dll")]
+        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
+        public const int WM_SYSCOMMAND = 0x0112;
+        public const int SC_MOVE = 0xF010;
+        public const int HTCAPTION = 0x0002;
+
+        Form FrmParent = null;
+        public FrmPaint(Form Frm)
+        {
+            InitializeComponent();
+            FrmParent = Frm;
+            this.Opacity = 0.4;
+            //this.MouseDown += Form_Base_MouseDown;
+        }
+
+        private void FrmPaint_Paint(object sender, PaintEventArgs e)
+        {
+            #region 圆形窗体
+            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();//创建一条线
+            path.AddEllipse(0, 0, Width-36, Height);//画一个椭圆 (x,y,宽,高)
+            //Graphics g = CreateGraphics();//为窗体创建画布
+            //g.DrawEllipse(new Pen(Color.Black, 1), 1, 1, Width , Height );//为画布画一个椭圆(笔,x,y,宽,高)
+            Region = new Region(path);//设置控件的窗口区域
+            #endregion
+        }
+
+        private void Form_Base_MouseDown(object sender, MouseEventArgs e)
+        {
+            ReleaseCapture();
+            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
+
+            int screenRight = Screen.PrimaryScreen.Bounds.Right;//屏幕右边缘
+            int formRight = this.Left + this.Size.Width;//窗口右边缘=窗口左上角x+窗口宽度
+            if (Math.Abs(screenRight - formRight) <= 150 || Math.Abs(formRight-screenRight)<=150)//往右靠
+                this.Location = new System.Drawing.Point(screenRight - this.Size.Width+30, this.Top);//当前窗口坐标赋值,实现吸附
+
+            if (Math.Abs(this.Left) <= 150)//往左靠
+                this.Location = new System.Drawing.Point(0, this.Top);
+
+            int screenBottom = Screen.PrimaryScreen.Bounds.Bottom;//屏幕下边缘
+            int formBottom = this.Top + this.Size.Height;//窗口下边缘
+            if (Math.Abs(screenBottom - formBottom) <= 150 || Math.Abs(formBottom-screenBottom) <= 150)//往下靠
+                this.Location = new System.Drawing.Point(this.Left, screenBottom - this.Size.Height);
+
+            if (Math.Abs(this.Top) <= 150)//往上靠
+                this.Location = new System.Drawing.Point(this.Left, 0);
+
+
+        }
+
+        private void FrmPaint_MouseDoubleClick(object sender, MouseEventArgs e)
+        {
+            if (FrmParent!=null)
+            {
+                FrmParent.Show();
+                FrmParent.WindowState = FormWindowState.Normal;
+                FrmParent.StartPosition = FormStartPosition.CenterScreen;
+                FrmParent.Focus();
+
+                //this.Close();
+                this.Hide();
+            }
+            else
+            {
+                MessageBox.Show("主程序被异常关闭,无法打开,请结束进程重新打开!");
+            }
+        }
+
+        private void FrmPaint_Load(object sender, EventArgs e)
+        {
+            int screenRight = Screen.PrimaryScreen.Bounds.Right;//屏幕右边缘
+            this.Location = new System.Drawing.Point(screenRight - this.Size.Width + 30, this.Top);
+        }
+
+        private void FrmPaint_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            if (e.CloseReason == CloseReason.UserClosing)
+            {
+                e.Cancel = true;    //取消"关闭窗口"事件
+                return;
+            }
+        }
+    }
+}

+ 120 - 0
DiodesADT/FrmPaint.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>