Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

I created a TRichEdit control, set the PlainText property to true, and set the font to a fixed-pitch font (e.g., Courier New). How do I set the tab stops so that the columns line up properly?

0
Posted

I created a TRichEdit control, set the PlainText property to true, and set the font to a fixed-pitch font (e.g., Courier New). How do I set the tab stops so that the columns line up properly?

0

This one took a remarkable length of time to solve. There are a few prefacing comments. First, this is only an issue if you are trying to display a formatted output with a fixed pitch font. This is common for source code editors and hexadecimal dumps where each character of output must line up with the character above it. If you are using a proportional font, then absolute offsets from the left margin are fine and you do not need this FAQ. Second, the native Rich Edit control allows you to set up to 32 tabstops (MAX_TAB_STOPS as defined in richedit.h) beyond that, you’re screwed. Third, tabstops are set in TWIPs relative to the left margin in the native Rich Edit control. The problem is converting character positions (as offsets) into absolute offsets in TWIPs. The offsets are, of course, dependent upon the font being used. All that said, the following code works for me.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.