C # form Move with Form shadow effect

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.