G
Guest
I'm trying to create a label control in VB.NET2005 that will automatically
change it's height to fit the content. To do that i'm using MeasureString to
determine required height for a set width.
What i found is that MeasureString sometimes returns the height which is
smaller then it should be and it seems to depended on the width.
So the question is am i doing something wrong or it's a bug. If it is a bug,
can someone recomend a reliable workaround.
Here is a code that used to test this. When width is set to 570, the last
line is not visible. When it's set to 590 all is OK.
Sub TestMeasureString(ByVal g As Graphics)
Dim s As Size
Dim f As Font = New Font("Arial", 11.25, FontStyle.Regular,
GraphicsUnit.Point)
Dim str As String = New String("W"c, 1000) & " END"
s = g.MeasureString(str, f, 570).ToSize
's = g.MeasureString(str, f, 590).ToSize
g.DrawRectangle(Pens.Black, New Rectangle(New Point(0, 0), s))
g.DrawString(str, f, Brushes.Black, New Rectangle(New Point(0, 0), s))
End Sub
change it's height to fit the content. To do that i'm using MeasureString to
determine required height for a set width.
What i found is that MeasureString sometimes returns the height which is
smaller then it should be and it seems to depended on the width.
So the question is am i doing something wrong or it's a bug. If it is a bug,
can someone recomend a reliable workaround.
Here is a code that used to test this. When width is set to 570, the last
line is not visible. When it's set to 590 all is OK.
Sub TestMeasureString(ByVal g As Graphics)
Dim s As Size
Dim f As Font = New Font("Arial", 11.25, FontStyle.Regular,
GraphicsUnit.Point)
Dim str As String = New String("W"c, 1000) & " END"
s = g.MeasureString(str, f, 570).ToSize
's = g.MeasureString(str, f, 590).ToSize
g.DrawRectangle(Pens.Black, New Rectangle(New Point(0, 0), s))
g.DrawString(str, f, Brushes.Black, New Rectangle(New Point(0, 0), s))
End Sub