This documentation is archived and is not being maintained.

How to: Create a Button

.NET Framework 3.0

This example shows how to create a Button.

Example

The following example creates a button and sets its Background, FontSize, FontWeight, FontFamily, and Content properties. The example adds the Button to a Canvas (cv2). It sets the font characteristics and background color of the button by using the properties of the SystemFonts and the SystemColors classes.

btncsharp = new Button();
btncsharp.Content = "Created with C# code.";
btncsharp.Background = SystemColors.ControlDarkDarkBrush;
btncsharp.FontSize = SystemFonts.CaptionFontSize;
cv2.Children.Add(btncsharp);

For the complete sample, see Buttons Sample.

See Also

Show: