Share via


How to: Create a Button That Has an Image

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

Example

The following example creates two Button controls. One Button contains text and the other contains an image. When a user clicks the Button that has the image, the background and the text of the other Button change.

This example creates Button controls by using markup but uses code to write the Click event handlers.

<Button Name="btn5" Width="50" Height="30" Click="OnClick5">
<Image Source="data\flower.jpg"></Image></Button>
<Button Name="btn6" BorderBrush="Black">Click the picture.</Button>
void OnClick5(object sender, RoutedEventArgs e)
{
    btn6.FontSize = 16;
    btn6.Content = "This is my favorite photo.";
    btn6.Background = Brushes.Red;
}
Sub OnClick5(ByVal sender As Object, ByVal e As RoutedEventArgs)
    btn6.FontSize = 16
    btn6.Content = "This is my favorite photo."
    btn6.Background = Brushes.Red
End Sub

For the complete sample, see Buttons Sample.

See Also

Tasks

How to: Create a Button
How to: Set the Background Property of a Button

Concepts

Button Overview

Other Resources

Buttons Sample
Button How-to Topics