Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Button Class

Represents a Windows button control, which reacts to the ButtonBase.Click event.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public ref class Button : public ButtonBase
public class Button extends ButtonBase
public class Button extends ButtonBase

The Button class inherits directly from the System.Windows.Controls.Primitives.ButtonBase class.

ContentModel: The Button control is a ContentControl, which means that a button can contain content such as text, images, or panels. For more information about the content model for Button, see Content Control Content Model.

Button has a distinct ButtonBase.Click event. Button invokes the OnMouseLeftButtonDown method handler to mark an event as handled. The button Click event handles the MouseLeftButtonDown event. Hence, if you try to attach an event handler for this event, it will never occur for a button. Instead, you must use PreviewMouseLeftButtonDown to obtain this functionality.

The following example shows how to create three buttons. The example creates two buttons of different colors and a third button that is labeled Reset Colors.

<Button Name="btn1" Background="Pink" BorderBrush="Black" BorderThickness="1" Click="OnClick1">
<Button Name="btn2" Background="LightBlue" BorderBrush="Black" BorderThickness="1" Click="OnClick2">
<Button Name="btn3" Click="OnClick3">Reset</Button>

More Code

How to: Create a Button That Has an Image

This example shows how to include an image on a Button.

How to: Create a Control That Has an Access Key and Text Wrapping

This example shows how to create a control that has an access key and supports text wrapping. The example uses a Label control to illustrate these concepts.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
© 2018 Microsoft