Form.TransparencyKey 属性

定义

获取或设置将表示窗体透明区域的颜色。Gets or sets the color that will represent transparent areas of the form.

public:
 property System::Drawing::Color TransparencyKey { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public System.Drawing.Color TransparencyKey { get; set; }
member this.TransparencyKey : System.Drawing.Color with get, set
Public Property TransparencyKey As Color

属性值

Color,表示要在窗体上透明显示的颜色。A Color that represents the color to display transparently on the form.

示例

下面的示例创建一个窗口,该窗口具有透明的客户端区域,而不考虑窗体的背景色。The following example creates a window that has a transparent client region regardless of background color of the form. 此示例要求在窗体类内定义示例方法。This example requires that the example method is defined within a form class.

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 Sub InitializeMyForm()
    BackColor = Color.Red
    ' Make the background color of form display transparently.
    TransparencyKey = BackColor
End Sub

注解

如果为 TransparencyKey 属性分配了 Color,则将以透明方式显示具有相同 BackColor 的窗体区域。When the TransparencyKey property is assigned a Color, the areas of the form that have the same BackColor will be displayed transparently. 在窗体的透明区域上执行的任何鼠标动作(例如鼠标单击)都将被传输到透明区域下的窗口。Any mouse actions, such as the click of the mouse, that are performed on the transparent areas of the form will be transferred to the windows below the transparent area. 例如,如果将窗体的客户端区域设为透明,则单击该区域中的鼠标会将单击的事件通知发送到其下的任何窗口。For example, if the client region of a form is made transparent, clicking the mouse on that area would send the event notification of the click to any window that is below it. 如果分配给 TransparencyKey 属性的颜色与窗体上的任何控件相同,它们也将以透明方式显示。If the color assigned to the TransparencyKey property is the same as any controls on the form, they also will be displayed transparently. 例如,如果在窗体上有一个将其 TransparencyKey 属性设置为 "SystemColors.Control" 的 Button 控件,则该控件将以透明方式显示,除非 Button 控件的 BackColor 属性更改为不同的颜色。For example, if you have a Button control on a form that has its TransparencyKey property set to SystemColors.Control, the control will be displayed transparently unless the BackColor property of the Button control is changed to a different color.

trueRightToLeftLayout 时,此属性不受支持。This property is not supported when RightToLeftLayout is true.

适用于