Using MeasureString to measure width of a blank space

  • Thread starter Thread starter Les2011
  • Start date Start date
L

Les2011

Guest
Hopefully there is a simple solution. I have the need to add 1,2 or 3 blank spaces and then to be able to measure the width of that string using the measureString method. What I noticed is if I set a string variable call it xyz=" " and depending on the font gives me a width of that string. However if I do xyz=" " the stringsize is the same as it was with 1 blank space?? Even if I make 3 blank spaces xyz=" " the stringsize.width is still the same. Following is a code snippet of what I have. I need to be able to add a number of blanks to a string and determine the width using measureString. When the space is placed on the picturebox I draw a red rectangle around it so I can see the space and when you run it and as you add more spaces to the variable it stays the same?? However it works fine for 1 space but after that is where my trouble is. My only thought that somehow all blanks after the first one is being truncated ???

Thanks

Les

Public Class Form1
Dim backbuffer As New Bitmap(750, 500)
Dim stringsize As SizeF
Public f1 As New Font("calibri", 24, FontStyle.Regular) 'calibri

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim g As Graphics
g = Graphics.FromImage(backbuffer)
PictureBox1.Image = backbuffer
g.Clear(Color.White)

Dim seg4 As String = " "
Dim x, y As Single
x = 50
y = 50
stringsize = g.MeasureString(seg4, f1)
g.DrawString(seg4, f1, New SolidBrush(Color.Black), x, y)
g.DrawRectangle(Pens.Red, x, y, stringsize.Width, stringsize.Height)
End Sub
End Class

Continue reading...
 
Back
Top