Icon inside of button?

How do i add an icon like in the screenshot below inside of a button? I cannot seem to find how to do it.

Answers


In WinForms use Button.Image (MSDN) like this:

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

and you can use Button.TextImageRelation Property to set the position of text and image relative to each other:

  • Overlay: image and text share the same space on a control.
  • ImageBeforeText: the image is displayed horizontally before the text of a control.
  • TextBeforeImage: the text is displayed horizontally before the image of a control.
  • ImageAboveText: the image is displayed vertically above the text of a control.
  • TextAboveImage: the text is displayed vertically above the image of a control.

If you put the button on the form, you can right click on it and click properties and then go to "Image" and put in the image you want, them go to the bottom and click "TextImageRelation" and click the drop down menu then click "ImageBeforeText", you can make it however you want but i personally like image before text the best.

Hope this helps.


Try this:

    <Button>
        <StackPanel Orientation="Horizontal">
            <Image Source="/Image/ok.png" />
            <TextBlock Text="Start Tasks" />
        </StackPanel>
    </Button>

WPF (and Silverlight) is offering a control called Image. As the name implies it's a container which can hold an image inside. Use such a control to represent the icon you want and then place it inside your Button through its Content property

like here:

<Button x:Name="btn_ControlRun">
    <StackPanel Orientation="Horizontal">
        <Image Stretch="Fill" Source="right.png"/>
        <Label Content="Start Tasks" />
    </StackPanel>
</Button>

Need Your Help

How to force a pdf download automatically?

pdf download

Is there any way to force the user's download-manager to start a download for .PDF instead of showing the .PDF in a new window/tab?

How to ignore route in asp.net forms url routing

c# asp.net url-routing axd ignoreroute

I am using the .NET 3.5 SP1 framework and I've implemented URL routing in my application. I was getting javascript errors: