按钮内的图标?

ale*_*y12 22 c#

如何在按钮内添加如下截图中的图标?我似乎无法找到如何做到这一点.

http://i.stack.imgur.com/6HGcK.jpg

Ria*_*Ria 27

在WinForms中使用Button.Image(MSDN),如下所示:

private void SetMyButtonIcon()
 {
    // Assign an image to the button.
    button1.Image = Image.FromFile("C:\\Graphics\\My.ico");
    // Align the image and text on the button.
    button1.ImageAlign = ContentAlignment.MiddleRight;    
    button1.TextAlign = ContentAlignment.MiddleLeft;
 }
Run Code Online (Sandbox Code Playgroud)

并且您可以使用Button.TextImageRelationProperty来设置文本和图像相对于彼此的位置:

  • Overlay:图像和文本在控件上共享相同的空间.
  • ImageBeforeText:图像在控件文本之前水平显示.
  • TextBeforeImage:文本在控件图像之前水平显示.
  • ImageAboveText:图像垂直显示在控件的文本上方.
  • TextAboveImage:文本垂直显示在控件的图像上方.


Doz*_*789 7

如果您将按钮放在表单上,​​可以右键单击它并单击属性,然后转到"图像"并输入所需的图像,它们将显示在底部并单击"TextImageRelation"并单击下拉菜单然后点击"ImageBeforeText",你可以随心所欲地制作它,但我个人喜欢文字前最好的形象.

希望这可以帮助.


kma*_*zek 6

试试这个:

    <Button>
        <StackPanel Orientation="Horizontal">
            <Image Source="/Image/ok.png" />
            <TextBlock Text="Start Tasks" />
        </StackPanel>
    </Button>
Run Code Online (Sandbox Code Playgroud)


mar*_*man 3

WPF(和 Silverlight)提供了一个名为Image. 顾名思义,它是一个可以在里面保存图像的容器。使用这样的控件来代表你想要的图标,然后Button通过它的方式将其放置在你的内部Content属性将其放置在你的内部

像这儿:

<Button x:Name="btn_ControlRun">
    <StackPanel Orientation="Horizontal">
        <Image Stretch="Fill" Source="right.png"/>
        <Label Content="Start Tasks" />
    </StackPanel>
</Button>
Run Code Online (Sandbox Code Playgroud)