国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

WPF設置窗體可以使用鼠標拖動大小的方法

2019-10-29 21:45:48
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了WPF設置窗體可以使用鼠標拖動大小的方法,涉及針對窗口的操作與設置技巧,具有很好的借鑒價值,需要的朋友可以參考下
 

本文實例講述了WPF設置窗體可以使用鼠標拖動大小的方法。分享給大家供大家參考。具體實現方法如下:

 

復制代碼代碼如下:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    // 獲取窗體句柄 
    IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;

 

    // 獲得窗體的 樣式 
    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的代碼:

復制代碼代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace SEsoft
{
    public class NativeMethods
    {
        /// <summary> 
        /// 帶有外邊框和標題的windows的樣式 
        /// </summary> 
        public const int WS_CAPTION = 0X00C0000;
 
        /// <summary> 
        /// window 擴展樣式 分層顯示 
        /// </summary> 
        public const int WS_EX_LAYERED = 0x00080000;
 
        /// <summary> 
        /// 帶有alpha的樣式 
        /// </summary> 
        public const int LWA_ALPHA = 0x00000002;
 
        /// <summary> 
        /// 顏色設置 
        /// </summary> 
        public const int LWA_COLORKEY = 0x00000001;
 
        /// <summary> 
        /// window的基本樣式 
        /// </summary> 
        public const int GWL_STYLE = -16;
 
        /// <summary> 
        /// window的擴展樣式 
        /// </summary> 
        public const int GWL_EXSTYLE = -20;
 
        /// <summary> 
        /// 設置窗體的樣式 
        /// </summary> 
        /// <param name="handle">操作窗體的句柄</param> 
        /// <param name="oldStyle">進行設置窗體的樣式類型.</param> 
        /// <param name="newStyle">新樣式</param> 
        [System.Runtime.InteropServices.DllImport("User32.dll")]
        public static extern void SetWindowLong(IntPtr handle, int oldStyle, int newStyle);
 
        /// <summary> 
        /// 獲取窗體指定的樣式. 
        /// </summary> 
        /// <param name="handle">操作窗體的句柄</param> 
        /// <param name="style">要進行返回的樣式</param> 
        /// <returns>當前window的樣式</returns> 
        [System.Runtime.InteropServices.DllImport("User32.dll")]
        public static extern int GetWindowLong(IntPtr handle, int style);
 
        /// <summary> 
        /// 設置窗體的工作區域. 
        /// </summary> 
        /// <param name="handle">操作窗體的句柄.</param> 
        /// <param name="handleRegion">操作窗體區域的句柄.</param> 
        /// <param name="regraw">if set to <c>true</c> [regraw].</param> 
        /// <returns>返回值</returns> 
        [System.Runtime.InteropServices.DllImport("User32.dll")]
        public static extern int SetWindowRgn(IntPtr handle, IntPtr handleRegion, bool regraw);
 
        /// <summary> 
        /// 創建帶有圓角的區域. 
        /// </summary> 
        /// <param name="x1">左上角坐標的X值.</param> 
        /// <param name="y1">左上角坐標的Y值.</param> 
        /// <param name="x2">右下角坐標的X值.</param> 
        /// <param name="y2">右下角坐標的Y值.</param> 
        /// <param name="width">圓角橢圓的width.</param> 
        /// <param name="height">圓角橢圓的height.</param> 
        /// <returns>hRgn的句柄</returns> 
        [System.Runtime.InteropServices.DllImport("gdi32.dll")]
        public static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int width, int height);
 
        /// <summary> 
        /// Sets the layered window attributes. 
        /// </summary> 
        /// <param name="handle">要進行操作的窗口句柄</param> 
        /// <param name="colorKey">RGB的值</param> 
        /// <param name="alpha">Alpha的值,透明度</param> 
        /// <param name="flags">附帶參數</param> 
        /// <returns>true or false</returns> 
        [System.Runtime.InteropServices.DllImport("User32.dll")]
        public static extern bool SetLayeredWindowAttributes(IntPtr handle, uint colorKey, byte alpha, int flags);
    }
}

 

希望本文所述對大家的WPF程序設計有所幫助。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 紫金县| 长寿区| 岐山县| 伊通| 遂平县| 济南市| 宁国市| 沅江市| 聂拉木县| 新田县| 通江县| 云南省| 宁阳县| 兴山县| 南城县| 克什克腾旗| 工布江达县| 邓州市| 广宗县| 罗定市| 五河县| 三台县| 和政县| 衡东县| 云南省| 镇雄县| 措美县| 叶城县| 察哈| 大理市| 监利县| 铁力市| 孝义市| 石景山区| 平乡县| 金湖县| 盐津县| 高要市| 高要市| 江油市| 南昌县|