【发布时间】:2012-12-27 23:00:14
【问题描述】:
如何在按钮内添加如下屏幕截图中的图标?我似乎找不到怎么做。
【问题讨论】:
-
感谢 Dante 添加图片 :)
-
WinForms, WPF, web???
-
@DanielMošmondor 或者我们可以给出 3 个答案,每个框架 1 个。很高兴来自谷歌并找到答案。
标签: c#
如何在按钮内添加如下屏幕截图中的图标?我似乎找不到怎么做。
【问题讨论】:
标签: c#
在 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;
}
您可以使用Button.TextImageRelation 属性来设置position of text and image 相对于彼此:
Overlay:图像和文本在控件上共享相同的空间。ImageBeforeText:图像在控件文本之前水平显示。TextBeforeImage:文本水平显示在控件图像之前。ImageAboveText:图像垂直显示在控件文本的上方。TextAboveImage:文本垂直显示在控件图像上方。【讨论】:
如果您将按钮放在表单上,您可以右键单击它并单击属性,然后转到“图像”并放入您想要的图像,它们会转到底部并单击“TextImageRelation”并单击下拉下拉菜单然后点击“ImageBeforeText”,你可以随意制作,但我个人最喜欢文字前的图像。
希望这会有所帮助。
【讨论】:
试试这个:
<Button>
<StackPanel Orientation="Horizontal">
<Image Source="/Image/ok.png" />
<TextBlock Text="Start Tasks" />
</StackPanel>
</Button>
【讨论】:
WPF(和 Silverlight)提供了一个名为 Image 的控件。顾名思义,它是一个可以在里面保存图像的容器。使用这样的控件来表示您想要的图标,然后通过其Content 属性将其放置在您的Button 中
喜欢这里:
<Button x:Name="btn_ControlRun">
<StackPanel Orientation="Horizontal">
<Image Stretch="Fill" Source="right.png"/>
<Label Content="Start Tasks" />
</StackPanel>
</Button>
【讨论】: