1 Attachment(s)
Re: Width of a tab sequence
The tab width of a text box obviously is 8 characters for a fixed-width font. That's pretty common and I haven't seen any way to change that. For a variable-width font (like the default of MS Sans Serif 8.25 pt) the tab width appears to be 8 digits.
BTW, your "longword" example even fits with the default font! :) (See attached image.)
Re: Width of a tab sequence
use String::Format with padding.
Re: Width of a tab sequence
Thanks for all who replied. I actually needed the answer right away and couldn't wait, so I alone figured things you said. I just switched to Courier font since it is of fixed-width, and started using padding method for strings, and everything now works the way I want.
Eri523, that example with iiiiiiiii and WWWWWW is exactly the problem I had, and the padding alone could not help. BTW, how is digit measured ? (you said tab is 8 digits for non-fixed size fonts)
1 Attachment(s)
Re: Width of a tab sequence
The size of a string in a certain font and font size can, for instance, be measured with an event handler like this little hack:
Code:
System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
Graphics ^gr = Graphics::FromHwnd(textBox1->Handle);
gr->PageUnit = GraphicsUnit::Point;
lblSize->Text = String::Concat("Text size: ", (gr->MeasureString(textBox1->Text, textBox1->Font)).ToString());
}
Well, "little" doesn't really mean "quick" here, as I had to scratch together the objects involved from all corners of the CTS. The Handle property of the text box, for instance, is not found in the docs on the TextBox class itself. It is rather inherited indirectly from the IWin32Window implementation in System::Windows::Forms::Control. Note that the Graphics object here is not used to actually draw something, but merely for the size calculation.
If you are interested in more elaborate information about this, feel free to ask. I was already thinking of writing a little text size calculator anyway and might post it here if you're interested. This would take some time to write, though.
The text size specification in the attached image has been generated by the code posted above, for instance. Note that the height specification is not equal to the font size because it accounts the entire line spacing rather than just the height of a norm character.
The width of a single digit in MS Sans Serif 8.25, BTW, is 7.47522 pt, measured using the same method. But the width measured for 8 digits is 40.15576 pt, which obviously is not 8 times the value for the single digit. :ehh: Maybe I should investigate some more about how that measurement actually works... :o
Re: Width of a tab sequence
Oh cool, I did not know that Graphics had the MeasureString method. :)