C#-WinForm-无边框窗体的移动和阴影-API
生活随笔
收集整理的這篇文章主要介紹了
C#-WinForm-无边框窗体的移动和阴影-API
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//窗體移動API,先導入命名空間,在委托MouseDown事件
//移動前準備
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
[DllImport("user32")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
private const int WM_SETREDRAW = 0xB;//窗體移動事件
private void Form1_MouseDown(object sender, MouseEventArgs e)
{if (this.WindowState == FormWindowState.Normal){ReleaseCapture();SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);}
} 無邊框窗體移動API
復制API代碼到窗體代碼結構函數下方,引用命名空間,委托MouseDown的事件(李獻策lxc)
//窗體陰影API,放在結構函數上方,修改結構函數即可const int CS_DropSHADOW = 0x20000;const int GCL_STYLE = (-26);[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern int GetClassLong(IntPtr hwnd, int nIndex);public Form1(){InitializeComponent();SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);} 窗體陰影API復制API代碼到結構函數上方,修改結構函數即可
?
API - 通用功能接口
做一個如下無邊框的窗體
一、無邊框窗體移動
復制API代碼到窗體代碼結構函數下方,引用命名空間,委托MouseDown的事件
public Form1(){InitializeComponent();}//窗體移動API[DllImport("user32.dll")]public static extern bool ReleaseCapture();[DllImport("user32.dll")]public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);public const int WM_SYSCOMMAND = 0x0112;public const int SC_MOVE = 0xF010;public const int HTCAPTION = 0x0002;[DllImport("user32")]private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);private const int WM_SETREDRAW = 0xB;private void Form1_MouseDown(object sender, MouseEventArgs e){if (this.WindowState == FormWindowState.Normal){ReleaseCapture();SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);}} 無窗體移動代碼 復制后二、窗體陰影
?
?
轉載于:https://www.cnblogs.com/qq450867541/p/6166477.html
總結
以上是生活随笔為你收集整理的C#-WinForm-无边框窗体的移动和阴影-API的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 合肥滨湖欣园停车位
- 下一篇: 2.8加密工具与散列