Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
Form Class
Form Properties
 TransparencyKey Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
Form.TransparencyKey Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Visual Basic (Declaration)
Public Property TransparencyKey As Color
Visual Basic (Usage)
Dim instance As Form
Dim value As Color

value = instance.TransparencyKey

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

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

public function set TransparencyKey (value : Color)

Property Value

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

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.

This property is not supported when RightToLeftLayout is true.

Windows 2000, Windows Server 2003, Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note: Transparent windows and regions are only supported starting with Windows 2000.

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.

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;
   }
J#
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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Bug      Đonny   |   Edit   |   Show History
Note that there is a bug in this property. See http://support.microsoft.com/kb/822495 for more.
Tags What's this?: bug (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker