700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > C# Winform 窗体美化(四 镂空窗体)

C# Winform 窗体美化(四 镂空窗体)

时间:2023-02-10 05:16:53

相关推荐

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;

这句代码可以使窗口透明。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。