更新:2007 年 11 月
默认情况下,控件不支持透明背景色。但是,通过使用构造函数中的 SetStyle 方法,可以让控件拥有不透明、透明或半透明的背景色。Control 类的 SetStyle 方法用于为控件设置特定的样式首选项,并可用来启用或禁用对透明背景色的支持。
| .gif) 说明: | 
|---|
| Windows 窗体控件不支持真正的透明。Windows 窗体透明控件的背景是由其父控件绘制的。 | 
使控件拥有透明背景色
- 定位控件类的构造函数。该构造函数出现在控件的代码文件中。在 C# 中,构造函数是与控件同名但没有返回值的方法。在 Visual Basic 中,构造函数是名为 New 的方法。 
- 在构造函数中调用窗体的 SetStyle。 - SetStyle(ControlStyles.SupportsTransparentBackColor, True)- SetStyle(ControlStyles.SupportsTransparentBackColor, true);- SetStyle(ControlStyles.SupportsTransparentBackColor, true);- 这将使控件能够支持透明背景色。 
- 在步骤 1 中添加的代码行下再添加下面的代码行。这会将控件的 BackColor 设置为 Transparent。 - Me.BackColor = Color.Transparent- this.BackColor = Color.Transparent;- this.set_BackColor(Color.get_Transparent());