none
How to properly determine position of tab stops for RichTextBox? RRS feed

  • Question

  • Hi there
    I'm trying to figure out where to set the tab-stops in a RichTextBox so that they will best accommodate the items I play on displaying in the box.

    That is, I know that I will want to display up to 16 characters in the first "column",  up to 11 characters in the second "column" and so on.

    I've learned that the tab-stops in an RTB are absolute positions - they are not based on the current selection font. And I assume these absolute positions are pixel units.

    So... how to go from knowing that the first tab stop should be at 17 characters to knowing the absolute value to set that tab stop at inside the RTB?

    My plan so far:

    Use a monospaced font, like Courier New, and use Measure String to get the width of any character. Multiply that by 17 and that should be my absolute position for the first tab stop.

    Of course, it's not that easy :-)  By default, when I create a Font it is using units of Points, not pixels, so I can't just git the point width and go multiplying that by 17.

    So then I got to thinking I could create a font using pixel units, in order to measure the width of a character. But I'm not sure how useful this will be because ultimately I probably will want to use point sizes to create the actual font - so now I'm kind of stuck on figuring out how to get the pixel size of a monospaced character, using a font specified in a given point size..??

    At least, I think that's the problem I need to solve!!

    Any ideas here would be very helpful!
    Michael
    Tuesday, November 11, 2008 12:48 AM