上個示例是C#調用windows api在原來代碼上加入窗體透明,控制項不透明代碼: 1 using System; 2 using System.Runtime.InteropServices; 3 using System.Windows.Forms; 4 5 namespace HoverTre
上個示例是C#調用windows api
在原來代碼上加入窗體透明,控制項不透明代碼:
1 using System; 2 using System.Runtime.InteropServices; 3 using System.Windows.Forms; 4 5 namespace HoverTreeWinForm 6 { 7 public partial class FormHewenqi : Form 8 { 9 10 /// <summary> 11 /// 使窗體透明 by 何問起 12 /// </summary> 13 protected override CreateParams CreateParams 14 { 15 get 16 { 17 18 CreateParams parameter = base.CreateParams; 19 parameter.ExStyle |= 0x00080000; 20 return parameter; 21 22 } 23 } 24 25 /// <summary> 26 /// http://hovertree.com/h/bjaf/v4y0b2l6.htm 27 /// </summary> 28 /// <returns></returns> 29 [DllImport("User32.dll")] 30 public static extern int MessageBox(int h, string m, string c, int type); 31 public FormHewenqi() 32 { 33 InitializeComponent(); 34 //使控制項不透明 35 this.TransparencyKey = BackColor; 36 } 37 38 private void button_hewenqi_Click(object sender, EventArgs e) 39 { 40 MessageBox(0, "Hello Win32 API HoverTree", "何問起網", 4); 41 } 42 43 private void linkLabel_help_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 44 { 45 System.Diagnostics.Process.Start("http://hovertree.com/h/bjaf/v4y0b2l6.htm"); 46 } 47 48 private void button_hoverc_Click(object sender, EventArgs e) 49 { 50 //獲取主窗體句柄 51 IntPtr h_handle = HewenqiUser32.GetCurrentWindowHandle(); 52 int h_jubing = 0; ; 53 if (h_handle != IntPtr.Zero) 54 h_jubing = (int)(h_handle); 55 MessageBox(h_jubing, "Hello hovertree.com", "歡迎光臨何問起", 4); 56 } 57 } 58 }
1、先把窗體的顏色變成一種很不常見的顏色。
2、把該窗體的TransparecyKey的顏色設置成窗體的顏色。
3、加入控制項,但是控制項的顏色不能和窗體顏色一致,否則控制項也透明。
運行程式後,就只能看見標題欄和控制項了。
轉自:http://hovertree.com/h/bjaf/i3lp7ay0.htm
演示下載:http://pan.baidu.com/s/1mhfgJ6C g56m
源碼下載:https://github.com/shangyuxian/HoverTree