本文實例講述了WPF設置窗體可以使用鼠標拖動大小的方法。分享給大家供大家參考。具體實現方法如下:
// 獲得窗體的 樣式
int oldstyle = NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_STYLE);
// 更改窗體的樣式為無邊框窗體
NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_STYLE, oldstyle & ~NativeMethods.WS_CAPTION);
// SetWindowLong(hwnd, GWL_EXSTYLE, oldstyle & ~WS_EX_LAYERED);
// 1 | 2 << 8 | 3 << 16 r=1,g=2,b=3 詳見winuse.h文件
// 設置窗體為透明窗體
NativeMethods.SetLayeredWindowAttributes(hwnd, 1 | 2 << 8 | 3 << 16, 0, NativeMethods.LWA_ALPHA);
// 創建圓角窗體 12 這個值可以根據自身項目進行設置
NativeMethods.SetWindowRgn(hwnd, NativeMethods.CreateRoundRectRgn(0, 0, Convert.ToInt32(this.ActualWidth), Convert.ToInt32(this.ActualHeight), 12, 12), true);
}
NativeMethods.cs的代碼:
希望本文所述對大家的WPF程序設計有所幫助。
新聞熱點
疑難解答