Form.TransparencyKey Form.TransparencyKey Form.TransparencyKey Form.TransparencyKey Property

定义

获取或设置将表示窗体透明区域的颜色。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 code 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 'InitializeMyForm

注解

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. 例如,如果你有Button具有窗体上的控件及其TransparencyKey属性设置为SystemColors.Control,该控件将以透明方式显示,除非BackColor属性Button控件更改为另一种颜色。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.

此属性不是支持何时RightToLeftLayouttrueThis property is not supported when RightToLeftLayout is true.

适用于