Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27379

Why can't I change the size of my Picturebox at runtime ?

$
0
0
Hi,

I would like to be able to re-size a picturebox at run time, so that it stays in proportion with the rest of the form if the user changes the size of the form.

vb.net Code:
  1. Private Sub Form1_SizeChanged(sender As System.Object, e As System.EventArgs) Handles MyBase.SizeChanged
  2.         Dim a, b As Double
  3.  
  4.         If F Then Exit Sub
  5.         a = Me.Width / Mw   'Change of width as multiple of size.
  6.         b = Me.Height / Mh  'Change of height as multiple of size.
  7.         If a > b Then       'Change PictureBox1 by lesser multiple to maintain ratio.
  8.             PictureBox1.Width = PictureBox1.Width * b
  9.             PictureBox1.Height = PictureBox1.Height * b
  10.         Else
  11.             PictureBox1.Width = PictureBox1.Width * a
  12.             PictureBox1.Height = PictureBox1.Height * a
  13.         End If
  14.  
  15.     End Sub
I would've thought this would do the trick but it doesn't. Watching it in De-Bug it all works correctly, except the dimensions of the pic'box don't change. Mw and Mh are global integer variables, set on initialisation to Me.Width and Me.Height respectively, and F is a global Boolean, initially 'True' re-set after initialisation.

Had this worked in the first trial, (or a subsequent one) I'd've changed "If a > b" to "If a > 1 And a > b" to get the largest pic'box which ever direction of change.

I might've also tried e.g. "PictureBox1.Width *= a"

Poppa.

Viewing all articles
Browse latest Browse all 27379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>