1

I would like to have a line aligned in such way, that some first words are aligned left and some last words are aligned right, but all are in the same line:

| text 1                           text2 |
| Lorem ipsum             dolor sit amet |

Is that possibile? How can I do that?

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
bartek
  • 505
  • 1
  • 4
  • 19

2 Answers2

1

As far as I know, the only way is to use tab stops. You simply create a right-justified tab stop at the very right edge. Then you have to write your text as

text 1\ttext2
Lorem ipsum\tdolor sit amet

where \t is a Tab character (i.e. U+0009).

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • This is ok, but I have several problems defining tabstops. For example I can't make Right-aligned tab work. I use RichEdit20.dll on windows 7 so setting pf.rgxTabs to 0x2000000 should work, am I wrong? – bartek May 11 '10 at 09:48
  • See http://msdn.microsoft.com/en-us/library/bb787942(v=VS.85).aspx: "Bits 24-27 can specify one of the following values to indicate the tab alignment. These bits do not affect the rich edit control display for versions earlier than Microsoft Rich Edit 3.0." – Andreas Rejbrand May 11 '10 at 09:55
  • But according to http://msdn.microsoft.com/en-us/library/bb787873(v=VS.85).aspx Riched20.dll corresponds to Microsoft Rich Edit 3.0 – bartek May 11 '10 at 10:12
  • @bartek: You shoud set rgxTabs to ThePositionOfTheRightEdge + 0x2000000. ThePositionOfTheRightEdge should be in the order or a few thousand "twips". But I am not able to make the tab stop right-aligned either... – Andreas Rejbrand May 11 '10 at 14:24
  • I just tried to create a RTF file in Microsoft Word 2007 that uses right-justified tab stops, and when I load the RTF file in my RichEdit control, the tab stop is indeed right-aligned, and the PARAFORMAT2 looks exactly as we expect. It is somewhat of a mystery why it does not work... – Andreas Rejbrand May 11 '10 at 15:03
  • Although generally a very ugly solution, it might be sufficient for your needs: You could create a RTF file in Microsoft Word and include it as a resource stream in your EXE, and then simply load it programmatically into the RichEdit control. Then, of course, you can alter the contents of the control programmatically, but retaining the right-aligned tab stop. If nothing else works, this might be *good enough* for your application. After all, many features of the RichEdit control are just to support reading of files created in Microsoft Word. – Andreas Rejbrand May 12 '10 at 08:31
1

I had this same problem, you need to send the message EM_SETTYPEPOGRAPHYOPTIONS to the control with wParam = TO_ADVANCEDTYPOGRAPHY, and lParam = TO_ADVANCEDTYPOGRAPHY, then right justifying using PARAFORMAT with the rgxTabs[ n ] += 0x2000000 works.

Sicco
  • 6,167
  • 5
  • 45
  • 61
nec
  • 11
  • 1