Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize picture on button in C#?

Im working with windows forms.I have a button with a image inside. When Im trying to resize the button, the image inside doesn't resizing (stays the same). How can I make image of the button to be sized with button?

Here is my code:

Image img = Image.FromStream(p);
devBtn = new Button();

devBtn.Image = img;
devBtn.Size = new Size((img.Width + 5), (img.Height + 5));
devBtn.Top = positionTOP;

Im trying to resize the button like this

this.devBtn.Height= pictureBox1.Top + e.Y;
this.devBtn.Width = pictureBox1.Left + e.X;
like image 353
DID Avatar asked Mar 25 '14 08:03

DID


1 Answers

Use Background Image of button as mentioned below it will solve your problem:

Image img = Image.FromStream(p);
devBtn = new Button();

devBtn.BackgroundImage = img;
devBtn.BackgroundImageLayout = ImageLayout.Stretch;

devBtn.Size = new Size((img.Width + 5), (img.Height + 5));
devBtn.Top = positionTOP;
like image 154
SpiderCode Avatar answered Nov 04 '22 10:11

SpiderCode