共用方式為


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

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

範例

下列範例會建立兩個 Button 控制項。 一個 Button 包含文字,另一個包含影像。 這個影像是位於範例專案資料夾底下名為 data 的子資料夾中。 使用者按一下有影像的 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>
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
void OnClick5(object sender, RoutedEventArgs e)
{
    btn6.FontSize = 16;
    btn6.Content = "This is my favorite photo.";
    btn6.Background = Brushes.Red;
}

請參閱

概念

控制項

其他資源

控制項程式庫