DID
DID

Reputation: 137

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;

Upvotes: 9

Views: 20281

Answers (1)

SpiderCode
SpiderCode

Reputation: 10122

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;

Upvotes: 13

Related Questions