次の方法で共有


How to: Create a Button

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);
Dim btnvb As Button
btnvb = New Button()
btnvb.Content = "Created with Visual Basic code."
btnvb.Background = SystemColors.ControlDarkDarkBrush
btnvb.FontSize = SystemFonts.CaptionFontSize
btnvb.FontWeight = SystemFonts.MessageFontWeight
btnvb.FontFamily = SystemFonts.CaptionFontFamily
cv2.Children.Add(btnvb)

For the complete sample, see Buttons Sample.

See Also

Tasks

How to: Create a Button That Has an Image
How to: Use System Resources to Style a Button

Concepts

Button Overview

Other Resources

Buttons Sample
Button How-to Topics