4

I have a button in my WinForms app and I added an image and text to it. I aligned the text to right and wanted to align the Background image to left but found out that it is not possible.

Is there any way to do that?

I have also tried to set just Image on the button but that couldn't be resized in the Button Properties.

May someone help me solve this out? Thanks so much.

In case that it is not possible I would have to resize every image in mspaint.

This is the result (as Background):

enter image description here

I need the BackgroundImage align to left.

This is result as Image when using align (not possible to resize)

enter image description here

Marek
  • 3,555
  • 17
  • 74
  • 123
  • Does this help `ImageAlign: MiddleRight TextAlign: MiddleLeft` Ref. http://stackoverflow.com/questions/507380/button-image-too-far-from-top-of-button-too-close-to-bottom-of-button – user1477388 Sep 05 '13 at 13:26

3 Answers3

8
  1. Use Image property to set your image (make sure it fits button height, you can change image size if you will open it from project resources folder)
  2. Set ImageAlign to MiddleLeft
  3. Set TextAlign to MiddleRight

Do not change anything else. I.e. TextImageRelation should be Overlay. Result:

enter image description here

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
  • Hello thank you for respond but I still got the same result except that the image is in the middle but top and button of image isn't visible because of the button height. Any suggestions please ? – Marek Sep 05 '13 at 13:40
  • @Marek are you using `Image` property to set image? Also make sure you provided correct alignment. Looks like you have default `MiddleCenter` alignment. – Sergey Berezovskiy Sep 05 '13 at 13:42
  • Thanks for your answer but at the final I resized that image to desired size 24x24 and it solved my problém. Thanks for everything. – Marek Sep 05 '13 at 13:46
6

Set these properties of Button.

ImageAlign to MiddleRight
TextImageRelation to ImageBeforeText
TextAlign as MiddleCenter

To have it resized on Button. See below:

Bitmap image = Bitmap.FromFile(oFile) as Bitmap;
Bitmap resized = new Bitmap(image, new Size(30, 30));
button1.Image = resized;
button1.Text = "Button";
button1.ImageAlign = ContentAlignment.MiddleLeft;
button1.TextImageRelation = TextImageRelation.ImageBeforeText;
button1.TextAlign = ContentAlignment.MiddleRight;
Irfan
  • 2,713
  • 3
  • 29
  • 43
  • `button1.TextImageRelation = TextImageRelation.ImageBeforeText;` This saved my day. I thought setting alignments were enough but it's this one that's necessary. – Lionet Chen Jul 12 '19 at 04:09
2

You can use the Image property instead of the BackgroundImage. You can set the align later using the ImageAlign property.

Moslem Ben Dhaou
  • 6,897
  • 8
  • 62
  • 93