Form.TransparencyKey 属性

获取或设置将表示窗体透明区域的颜色。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property TransparencyKey As Color
用法
Dim instance As Form
Dim value As Color

value = instance.TransparencyKey

instance.TransparencyKey = value
public Color TransparencyKey { get; set; }
public:
property Color TransparencyKey {
    Color get ();
    void set (Color value);
}
/** @property */
public Color get_TransparencyKey ()

/** @property */
public void set_TransparencyKey (Color value)
public function get TransparencyKey () : Color

public function set TransparencyKey (value : Color)

属性值

Color,表示要在窗体上透明显示的颜色。

备注

当将 Color 分配给 TransparencyKey 属性时,具有相同 BackColor 的窗体区域将透明显示。在窗体的透明区域执行的任何鼠标操作(如鼠标单击)都将传输到该透明区域下的窗口。例如,如果使窗体的工作区透明,则在该区域上单击鼠标会将单击的事件通知发送到该区域下的任何窗口。如果分配给 TransparencyKey 属性的颜色与窗体上的任何控件相同,则这些控件也将透明显示。例如,当某窗体的 TransparencyKey 属性设置为 SystemColors.Control 时,如果在该窗体上有一个 Button 控件,则该控件将透明显示,除非将 Button 控件的 BackColor 属性更改为其他颜色。

RightToLeftLayouttrue 时,不支持此属性。

Windows 2000, Windows Server 2003, Windows XP Home Edition、Windows XP Professional x64 Edition、Windows Server 2003 平台说明: 只有在从 Windows 2000 启动时,才支持透明的窗口及区域。

示例

无论窗体的背景色是什么,下面的代码示例都创建一个具有透明工作区的窗口。此示例要求已经在窗体类内定义了该示例方法。

Public Sub InitializeMyForm()
    BackColor = Color.Red
    ' Make the background color of form display transparently.
    TransparencyKey = BackColor
End Sub 'InitializeMyForm
public void InitializeMyForm()
 {
    this.BackColor = Color.Red;
    // Make the background color of form display transparently.
    this.TransparencyKey = BackColor;
 }
    
public:
   void InitializeMyForm()
   {
      this->BackColor = Color::Red;
      // Make the background color of form display transparently.
      this->TransparencyKey = BackColor;
   }
public void InitializeMyForm()
{
    this.set_BackColor(Color.get_Red());

    // Make the background color of form display transparently.
    this.set_TransparencyKey(this.get_BackColor());
} //InitializeMyForm

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Form 类
Form 成员
System.Windows.Forms 命名空间