1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 using System.Runtime.InteropServices; 11 12 namespace Mform 13 { 14 public partial class Form1 : Form 15 { 16 [DllImport("user32.dll")] 17 public static extern bool ReleaseCapture(); 18 [DllImport("user32.dll")] 19 public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); 20 public Form1() 21 { 22 InitializeComponent(); 23 } 24 25 protected override void OnLoad(EventArgs e) 26 { 27 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;//设置窗体默认属性 28 base.OnLoad(e); 29 } 30 protected override void OnMouseDown(MouseEventArgs e) 31 { 32 ReleaseCapture(); 33 SendMessage(this.Handle, 0x0112, 0xF010 + 0x0002, 0);//调用Api 34 base.OnMouseDown(e); 35 } 36 } 37 }
此方法重写窗体的