Features
- Draw a hollow form
- The buttons on the form are not transparent
1. Introduction
Hollowed form, although transparent form can be realized, it does not realize transparency in the true sense. Click the form to click the form behind the form.
2. Effect display
Three, code implementation
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 通用测试平台
{
public partial class Form1 : Form
{
#region 变量
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);
#endregion
#region 构造函数
public Form1()
{
InitializeComponent();
SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, 0x00FF00, 255, LWA_COLORKEY);
}
#endregion
#region 窗体初始化
private void Form1_Load(object sender, EventArgs e)
{
//开启透明窗体
TransparencyKey = BackColor;
}
#endregion
}
}