C# Winform 窗体美化(四、镂空窗体)
生活随笔
收集整理的這篇文章主要介紹了
C# Winform 窗体美化(四、镂空窗体)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
四、鏤空窗體
例子下載
直接貼效果圖吧:
1、控件的透明
2、窗體的透明
代碼如下:
public partial class Form1 : Form {public Form1(){InitializeComponent();SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_LAYERED);SetLayeredWindowAttributes(Handle, 0x00FF00, 255, LWA_COLORKEY);//替換某種顏色為透明(0x00FF00:綠色)}private const uint WS_EX_LAYERED = 0x80000;//異形窗體特效的實現private const int GWL_EXSTYLE = -20;//設定一個新的擴展風格private const int LWA_COLORKEY = 1;//透明方式[DllImport("user32", EntryPoint = "SetWindowLong")]//改變指定窗口的屬性private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]//設置分層窗口透明度private static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, int bAlpha, int dwFlags);private void Form1_Load(object sender, EventArgs e){//TransparencyKey = BackColor;} }注意:
TransparencyKey = BackColor;
這句代碼可以使窗口透明。
總結
以上是生活随笔為你收集整理的C# Winform 窗体美化(四、镂空窗体)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: npm上传自己的项目
- 下一篇: C# Winform 使用二维码