G
Guest
Hi,
I have a TextBox that is set to a certain width. From this, I need to
figure out the max number of characters that can fit into the TextBox. I'm
using Courier New font, size 8.25.
I've played around with MeasureText, trying to measure one character (using
Courier New results in each character being the same width) and dividing the
width of the TextBox minus the borders by this value, but it is not working
correctly. It is close, but not quite on. For instance, if my TextBox is
500 wide, my formula tells me that I should be able to fit 75 characters in
the TextBox, but only 72 fit in before it starts scrolling.
I'm obviously missing something, but I'm not sure what. The MeasureText
that I'm using looks like:
txtTest.CreateGraphics.MeasureString("1", txtTest.Font, 10000,
StringFormat.GenericTypographic).Width)
where txtText is using Courier New, 8.25. I've tried it with different
sizes of the font and I get the same results.
Anyone have any ideas that might help me work this out?
Thanks
I have a TextBox that is set to a certain width. From this, I need to
figure out the max number of characters that can fit into the TextBox. I'm
using Courier New font, size 8.25.
I've played around with MeasureText, trying to measure one character (using
Courier New results in each character being the same width) and dividing the
width of the TextBox minus the borders by this value, but it is not working
correctly. It is close, but not quite on. For instance, if my TextBox is
500 wide, my formula tells me that I should be able to fit 75 characters in
the TextBox, but only 72 fit in before it starts scrolling.
I'm obviously missing something, but I'm not sure what. The MeasureText
that I'm using looks like:
txtTest.CreateGraphics.MeasureString("1", txtTest.Font, 10000,
StringFormat.GenericTypographic).Width)
where txtText is using Courier New, 8.25. I've tried it with different
sizes of the font and I get the same results.
Anyone have any ideas that might help me work this out?
Thanks