resizing picture box based on string length

  • Thread starter Thread starter microsoft
  • Start date Start date
M

microsoft

I want to resize the width of a picture box based on the length of a string.

I have a string "s".

I do this in the paint event of a picturebox:

Dim font As New Font("Arial", 12, FontStyle.Regular)
Dim sSize as SizeF = e.graphics.measurestring(s, font)

'Here's what i want to do that doesn't work

If PictureBox1.width < sSize then
PictureBox1.width = sSize
End if

---- I get the error "< operator is not defined for System.Drawing.Size
 
You need to use the Width property of the SizeF struct.

Dim width As Integer = Convert.ToInt32(sSize.Width)
If PictureBox1.Width < width Then
PictureBox1.Width = width
End If
 
cool. thanx.
Tim Wilson said:
You need to use the Width property of the SizeF struct.

Dim width As Integer = Convert.ToInt32(sSize.Width)
If PictureBox1.Width < width Then
PictureBox1.Width = width
End If
 
and it worked! Thanks so much for responding and even on the Memorial Day
Weekend. We probably both need to get a life. Well, me at least.
 
Back
Top