This documentation is archived and is not being maintained.

Form.TransparencyKey Property

Gets or sets the color that will represent transparent areas of the form.

[Visual Basic]
Public Property TransparencyKey As Color
[C#]
public Color TransparencyKey {get; set;}
[C++]
public: __property Color get_TransparencyKey();
public: __property void set_TransparencyKey(Color);
[JScript]
public function get TransparencyKey() : Color;
public function set TransparencyKey(Color);

Property Value

A Color that represents the color to display transparently on the form.

Remarks

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. If the color assigned to the TransparencyKey property is the same as any controls on the form, they also will be displayed transparently. 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.

Windows 2000 Platform Note:  Transparent windows and regions are only supported under the Windows 2000 operating system.

Example

[Visual Basic, C#, C++] The following example creates a window that has a transparent client region regardless of background color of the form. This example assumes that the example method is defined within a form class.

[Visual Basic] 
Public Sub InitializeMyForm()
    BackColor = Color.Red
    ' Make the background color of form display transparently.
    TransparencyKey = BackColor
End Sub 'InitializeMyForm

[C#] 
public void InitializeMyForm()
 {
    this.BackColor = Color.Red;
    // Make the background color of form display transparently.
    this.TransparencyKey = BackColor;
 }
    

[C++] 
public:
void InitializeMyForm()
 {
    this->BackColor = Color::Red;
    // Make the background color of form display transparently.
    this->TransparencyKey = BackColor;
 }
    

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Form Class | Form Members | System.Windows.Forms Namespace

Show: