1

I have a PictureBox and a Button inside a Form. The PictureBox fill the Form and the SizeMode property is set to StretchImage.

When i click the button I want to change the image size (bigger), and I want also that the scrollbars appear.

So, I change the Size property of my PictureBox on the click event:

pictureBox1.Size = new Size(800, 800);

but this code does not have any effect.
Why?


I also tried to redraw the image itself (using GDI commands), but in this way the scrollbars do not appear.


How can I solve this problem? Thanks.

Nick
  • 10,309
  • 21
  • 97
  • 201
  • Are you setting the dock mode of your picture box? – Mark Hall Oct 06 '12 at 19:40
  • @MarkHall yes it fills (Dock = Fill) the form. – Nick Oct 06 '12 at 19:42
  • You will not be able to get scrollbars then, because with your SizeMode set to StretchImage and your Dock set to fill the PictureBox will always be the size of your client area and your Picture will be sized to fit it. – Mark Hall Oct 06 '12 at 19:44
  • @MarkHall so, what I have to do to resize my image having the scrollbars? – Nick Oct 06 '12 at 19:48
  • Take a look at this http://stackoverflow.com/questions/4710145/how-can-i-get-scrollbars-on-picturebox – Mark Hall Oct 06 '12 at 20:00

1 Answers1

2

Set:

pictureBox1.Bounds = this.ClientRectangle;
pictureBox1.Dock = DockStyle.None;

for your PictureBox and you will be able to resize the PictureBox itself.

gliderkite
  • 8,828
  • 6
  • 44
  • 80