Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Icon inside of button?

Tags:

c#

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

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

like image 508
alexy12 Avatar asked Jul 14 '12 12:07

alexy12


1 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.
like image 66
Ria Avatar answered Oct 04 '22 10:10

Ria