Reputation: 3575
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):
I need the BackgroundImage align to left.
This is result as Image when using align (not possible to resize)
Upvotes: 4
Views: 15699
Reputation: 2771
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;
Upvotes: 6
Reputation: 236208
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)ImageAlign
to MiddleLeft
TextAlign
to MiddleRight
Do not change anything else. I.e. TextImageRelation
should be Overlay
. Result:
Upvotes: 8
Reputation: 7005
You can use the Image
property instead of the BackgroundImage
. You can set the align later using the ImageAlign
property.
Upvotes: 2