I am currently using following code to estimate the size of the textbox:
Dim i As Integer, j As Integer, pGr As Graphics, sz As SizeF
For i = 1 To pNumRows
For j = 1 To pWidth
sb.Append("W")
Next
If pNumRows > 1 Then
sb.Append(vbCrLf)
End If
Next
pGr = txtTextBox.CreateGraphics
sz = pGr.MeasureString(sb.ToString, pTextFont, New SizeF(10000, 10000))
pGr.Dispose()
txtTextBox.SetSize(CInt(sz.Width), CInt(sz.Height) + 80)
txtTextBox.Size = New Size(CInt(sz.Width) + 20, CInt(sz.Height) + 100)
I was wondering if there is any way to remove the for-loops and do away entirely with the pGr (textbox.CreateGraphics) method and still correctly estimate the size of the textbox. Any help will be greatly appreciated.
If you’re wondering why I am (actually the person who wrote the code) is looping through all the ‘W’, it’s because (I think) ‘W’ has the biggest width and height in the entire character set, so the person (who wrote the code) is trying to guess the maximum area needed.
This eliminates your loops (and replaces with them loops in the framework, hopefully faster ones). Not sure about performance.