VB6, GDI . . .
If I have a textbox, and I want to resize the font so that the textbox width can only contain a certain number of characters regardless of size how do I calculate the font size?
Thanks in advance
Printable View
VB6, GDI . . .
If I have a textbox, and I want to resize the font so that the textbox width can only contain a certain number of characters regardless of size how do I calculate the font size?
Thanks in advance
I'm not sure what the property is called, but it lets you set the max number of characters allowed in a textbox, for now I'll call it MaxChars. You would want to play with these values since I don't have vb on this computer, I'm not sure if it works, but it would look somewhat like this:
Now I don't know if this will work, but the goal is that the larger the font the less characters allowed. (Actually that doesn't work at all, and I don't have time to figure out what will, but you should have a general idea of how you would go about doing it)vb Code:
text1.MaxChars = (text1.font.size / 2) - text1.font.size
[vbcode]
txtEdit.MaxLength = uField.Geometry.LineQty * uField.Geometry.LineLength
lWidth = txtEdit.Width
lFontSize = 72 * 1.5 * (lWidth / GetDeviceCaps(picDocument.hdc, LOGPIXELSY))
lFontSize = lFontSize / uField.Geometry.LineLength
txtEdit.FontSize = lFontSize
[/vbcode]
Seems to work quite nice indeed!
Cheers.