方法1:
//this.BackColor = Color.White;
//this.TransparencyKey = Color.White;
结论:
窗体透明,控件不透明,边框不透明
方法2:
this.Opacity = 0.0;
结论:
窗体和控件都透明
方法3
[DllImport("User32.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);
private void Draw()
{
g.Clear(Color.Transparent);
//System.IntPtr DesktopHandle = GetDC(System.IntPtr.Zero);
//Graphics g = Graphics.FromHdc(DesktopHandle);
//g.DrawRectangle(new Pen(Color.Red), new Rectangle(10, 10, 100, 100));
}
结论:
g.Clear(Color.Transparent);的时候,整个屏幕都是黑色的
方法4:
修改上一个例子,在窗体上绘制
Graphics g = this.CreateGraphics();
绘制的内容也是透明的
方法5:
在方法1的基础上,把窗体的边框样式设为Nome(this.FormBorderStyle = FormBorderStyle.None;),如果需要关闭,则添加一个仿关闭按钮即可