Form..::.TransparencyKey Property
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.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)
Syntax

'Usage

Dim instance As Form
Dim value As Color

value = instance.TransparencyKey

instance.TransparencyKey = value

'Declaration

Public Property TransparencyKey As Color

Property Value

Type: System.Drawing..::.Color
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.

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.

Examples

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


Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View