Steps
1. Import Code
2. Add the Form_1mousedown function to the event
3. Define the AnimateWindow statement in the load function, and note that there are two references.
4.DllImport If there is an error, press SHIFT+ALT+F10 to add the first solution
[System.Runtime.InteropServices.DllImport ("user32.dll")]//api Load Declaration
protected static extern bool AnimateWindow (IntPtr hWnd, int dwtime, int dwFlags);//Definition AnimateWindow
Public Const Int32 Aw_blend = 0x00080000;
Public Const Int32 Aw_center = 0x00000010;
Public Const Int32 aw_activate = 0x00020000;
Public Const Int32 Aw_hide = 0x00010000;
Public Const Int32 Aw_slide = 0x00040000;
Public Form1 ()
{
InitializeComponent ();
Setclasslong (this. Handle, Gcl_style, Getclasslong (this. Handle, Gcl_style) | Cs_dropshadow);//api function loading
To implement the form border shadow effect
This. SetStyle (Controlstyles.userpaint | Controlstyles.allpaintinginwmpaint |
Controlstyles.optimizeddoublebuffer, True);
}
Drag Code #region Form
//
public const int wm_nclbuttondown = 0XA1;
public const int htcaption = 0x2;
[DllImportAttribute ("User32.dll")]
public static extern int SendMessage (IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute ("User32.dll")]
public static extern bool ReleaseCapture ();
private void Form1_mousedown (object sender, MouseEventArgs e)//manually added in form event, note reference, no reference to complete
{
ReleaseCapture ();
SendMessage (Handle, Wm_nclbuttondown, htcaption, 0);
}
#endregion
#region Form Border Shadow effect
const int Cs_dropshadow = 0x20000;
const int Gcl_style = (-26);
Declaring the Win32 API
[DllImport ("user32.dll", CharSet = CharSet.Auto)]
public static extern int Setclasslong (INTPTR hwnd, int nIndex, int denewlong);
[DllImport ("user32.dll", CharSet = CharSet.Auto)]
public static extern int Getclasslong (INTPTR hwnd, int nIndex); #endregion
private void Form1_Load (object sender, EventArgs e)
{
AnimateWindow (this. Handle, Aw_blend | Aw_center | Aw_activate);
}
private void Form1_formclosing (object sender, FormClosingEventArgs e)
{
AnimateWindow (this. Handle, Aw_center | Aw_blend | Aw_hide);
}
C # form Move with Form shadow effect