Share via


HOW TO:建立具有影像的按鈕

更新:2007 年 11 月

本範例說明如何將影像加入到 Button

範例

下列範例會建立兩個 Button 控制項。一個 Button 包含文字,另一個包含影像。使用者按一下有影像的 Button 時,另一個 Button 的背景和文字會改變。

這個範例會使用標記建立 Button 控制項,但用程式碼撰寫 Click 事件處理常式。

<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;
}
Private 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

請參閱

工作

Buttons Sample

概念

控制項概觀

其他資源

控制項程式庫