设置窗体透明C#代码
2016-02-25 23:26
441 查看
上个示例是C#调用windows api
在原来代码上加入窗体透明,控件不透明代码:
1、先把窗体的颜色变成一种很不常见的颜色。
2、把该窗体的TransparecyKey的颜色设置成窗体的颜色。
3、加入控件,但是控件的颜色不能和窗体颜色一致,否则控件也透明。
运行程序后,就只能看见标题栏和控件了。
转自:http://hovertree.com/h/bjaf/i3lp7ay0.htm
演示下载:http://pan.baidu.com/s/1mhfgJ6C g56m
源码下载:https://github.com/shangyuxian/HoverTree
在原来代码上加入窗体透明,控件不透明代码:
using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace HoverTreeWinForm { public partial class FormHewenqi : Form { /// <summary> /// 使窗体透明 by 何问起 /// </summary> protected override CreateParams CreateParams { get { CreateParams parameter = base.CreateParams; parameter.ExStyle |= 0x00080000; return parameter; } } /// <summary> /// http://hovertree.com/h/bjaf/v4y0b2l6.htm /// </summary> /// <returns></returns> [DllImport("User32.dll")] public static extern int MessageBox(int h, string m, string c, int type); public FormHewenqi() { InitializeComponent(); //使控件不透明 this.TransparencyKey = BackColor; } private void button_hewenqi_Click(object sender, EventArgs e) { MessageBox(0, "Hello Win32 API HoverTree", "何问起网", 4); } private void linkLabel_help_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://hovertree.com/h/bjaf/v4y0b2l6.htm"); } private void button_hoverc_Click(object sender, EventArgs e) { //获取主窗体句柄 IntPtr h_handle = HewenqiUser32.GetCurrentWindowHandle(); int h_jubing = 0; ; if (h_handle != IntPtr.Zero) h_jubing = (int)(h_handle); MessageBox(h_jubing, "Hello hovertree.com", "欢迎光临何问起", 4); } } }
1、先把窗体的颜色变成一种很不常见的颜色。
2、把该窗体的TransparecyKey的颜色设置成窗体的颜色。
3、加入控件,但是控件的颜色不能和窗体颜色一致,否则控件也透明。
运行程序后,就只能看见标题栏和控件了。
转自:http://hovertree.com/h/bjaf/i3lp7ay0.htm
演示下载:http://pan.baidu.com/s/1mhfgJ6C g56m
源码下载:https://github.com/shangyuxian/HoverTree
相关文章推荐