L
Les2011
Guest
I cant seem to figure out why there is a good amount of space after the text that I draw onto a picturebox. Basically I set up the size of the picturebox to be equal to the largest width and height and resize my buffer before actually drawing to the object.
Following is my code snippet:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
'place a panel on the form and inside of it place a picturebox
'and place the following code inside of a button control
Dim backbuffer As New Bitmap(Panel1.Width, Panel1.Height)
Dim t As String = "This is a test12345678901234567890123456789k"
Dim x, y As Single
Using g As Graphics = Graphics.FromImage(backbuffer),
f1 = New Font("calabri", 24, FontStyle.Regular),
fmt As StringFormat = CType(StringFormat.GenericTypographic.Clone, StringFormat)
fmt.FormatFlags = fmt.FormatFlags Or StringFormatFlags.MeasureTrailingSpaces
Dim stringsize As SizeF
stringsize = g.MeasureString(t, f1, New Point(CInt(0), CInt(0)), fmt)
x = stringsize.Width
y = stringsize.Height
End Using
If x < Panel1.Width Then
x = Panel1.Width
End If
If y < Panel1.Height Then
y = Panel1.Height
End If
backbuffer.Dispose()
backbuffer = New Bitmap(CInt(x), CInt)
Using g As Graphics = Graphics.FromImage(backbuffer)
g.Clear(Color.White) 'paint the buffer white
g.DrawString(t, New Font("Calibri", 24, FontStyle.Regular), New SolidBrush(Color.Black), New Point)
End Using
PictureBox1.Image = backbuffer
PictureBox1.Size = backbuffer.Size
End Sub
Thanks for any help
Les
Continue reading...
Following is my code snippet:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
'place a panel on the form and inside of it place a picturebox
'and place the following code inside of a button control
Dim backbuffer As New Bitmap(Panel1.Width, Panel1.Height)
Dim t As String = "This is a test12345678901234567890123456789k"
Dim x, y As Single
Using g As Graphics = Graphics.FromImage(backbuffer),
f1 = New Font("calabri", 24, FontStyle.Regular),
fmt As StringFormat = CType(StringFormat.GenericTypographic.Clone, StringFormat)
fmt.FormatFlags = fmt.FormatFlags Or StringFormatFlags.MeasureTrailingSpaces
Dim stringsize As SizeF
stringsize = g.MeasureString(t, f1, New Point(CInt(0), CInt(0)), fmt)
x = stringsize.Width
y = stringsize.Height
End Using
If x < Panel1.Width Then
x = Panel1.Width
End If
If y < Panel1.Height Then
y = Panel1.Height
End If
backbuffer.Dispose()
backbuffer = New Bitmap(CInt(x), CInt)
Using g As Graphics = Graphics.FromImage(backbuffer)
g.Clear(Color.White) 'paint the buffer white
g.DrawString(t, New Font("Calibri", 24, FontStyle.Regular), New SolidBrush(Color.Black), New Point)
End Using
PictureBox1.Image = backbuffer
PictureBox1.Size = backbuffer.Size
End Sub
Thanks for any help
Les
Continue reading...