Ver Fonte

修改问题初始化窗口不能移动

HaoShuang há 4 anos atrás
pai
commit
93ef0175c2

+ 9 - 5
HOZProject/FormHOZMain.cs

@@ -84,7 +84,7 @@ namespace HOZProject
         /// <summary>
         /// 显示实例化窗体
         /// </summary>
-        Form m_FormInit = null;
+        FormMove m_FormInit = null;
 
         /// <summary>
         /// 是否已保存
@@ -527,15 +527,19 @@ namespace HOZProject
             }
             if (m_FormInit == null)
             {
-                m_FormInit = new Form();
+                m_FormInit = new FormMove();
             }
             m_FormInit.StartPosition = FormStartPosition.CenterScreen;
             m_FormInit.FormBorderStyle = FormBorderStyle.None;
-            m_FormInit.Width = uControl_Init.Width;
-            m_FormInit.Height = uControl_Init.Height;
+            m_FormInit.Width = uControl_Init.Width+ 20;
+            m_FormInit.Height = uControl_Init.Height + 20;
+            
             if (m_FormInit.Controls.Count == 0)
             {
+                uControl_Init.Location = new Point(10,10);
+               
                 m_FormInit.Controls.Add(uControl_Init);
+                
             }
             m_FormInit.ShowDialog();
         }
@@ -775,7 +779,7 @@ namespace HOZProject
                 ReleaseCapture();
                 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
             }
-        } 
+        }      
         #endregion
 
         #region 开始、结束线程事件

+ 49 - 0
HOZProject/FormMove.Designer.cs

@@ -0,0 +1,49 @@
+namespace HOZProject
+{
+    partial class FormMove
+    {
+        /// <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.SuspendLayout();
+            // 
+            // FormMove
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.BackColor = System.Drawing.SystemColors.ControlDarkDark;
+            this.ClientSize = new System.Drawing.Size(800, 450);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+            this.Name = "FormMove";
+            this.Text = "Form1";
+            this.Load += new System.EventHandler(this.FormMove_Load);
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+    }
+}

+ 61 - 0
HOZProject/FormMove.cs

@@ -0,0 +1,61 @@
+using FileManager;
+using MeasureData;
+using MeasureThread;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Configuration;
+using System.Data;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using static MeasureThread.ThreadStatusEventArgs;
+
+namespace HOZProject
+{
+    public partial class FormMove : Form
+    {
+        public FormMove()
+        {
+            InitializeComponent();
+        }
+
+        #region 拖动无窗体的控件
+        [DllImport("user32.dll")]//拖动无窗体的控件
+        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;
+        private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
+        {
+            if (this.WindowState == FormWindowState.Normal)
+            {
+                //拖动窗体
+                ReleaseCapture();
+                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
+            }
+        }
+        private void Form_MouseDown(object sender, MouseEventArgs e)
+        {
+            if (this.WindowState == FormWindowState.Normal)
+            {
+                //拖动窗体
+                ReleaseCapture();
+                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
+            }
+        }
+        #endregion
+
+        private void FormMove_Load(object sender, EventArgs e)
+        {
+            //加载窗口移动事件
+            this.MouseDown += new MouseEventHandler(Form_MouseDown);
+        }
+    }
+}

+ 120 - 0
HOZProject/FormMove.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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 9 - 0
HOZProject/UnitControl.csproj

@@ -50,6 +50,12 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Colors\TextColors.cs" />
+    <Compile Include="FormMove.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="FormMove.Designer.cs">
+      <DependentUpon>FormMove.cs</DependentUpon>
+    </Compile>
     <Compile Include="FormHOZMain.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -112,6 +118,9 @@
     <EmbeddedResource Include="FormHOZMain.resx">
       <DependentUpon>FormHOZMain.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="FormMove.resx">
+      <DependentUpon>FormMove.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="FormShowImage.resx">
       <DependentUpon>FormShowImage.cs</DependentUpon>
     </EmbeddedResource>

+ 2 - 16
HOZProject/UserControls/UControl_Init.cs

@@ -13,6 +13,7 @@ using FileManager;
 using System.IO;
 using System.Runtime.InteropServices;
 
+
 namespace HOZProject
 {
     public partial class UControl_Init : UserControl
@@ -1008,21 +1009,6 @@ namespace HOZProject
             }
         }
 
- #region 拖动控件
-        [DllImportAttribute("user32.dll")]
-        private extern static bool ReleaseCapture();
-        [DllImportAttribute("user32.dll")]
-        private extern static int SendMessage(IntPtr handle, int m, int p, int h);
-        private void panelEx4_MouseDown(object sender, MouseEventArgs e)
-        {
-            //DevComponents.DotNetBar.PanelEx p = (DevComponents.DotNetBar.PanelEx)sender;
-            //if (e.Button == MouseButtons.Left)
-            //{
-            //    this.Cursor = Cursors.SizeAll;
-            //    ReleaseCapture();
-            //    SendMessage(p.Handle, 0xA1, 0x2, 0); this.Cursor = Cursors.Default;
-            //}
-        }
-        #endregion
+
     }
 }