views:

42

answers:

0

Using the Text property of a WinForms' RichTextBox, you can show a letter with an accent above it, in a way that the letter is one character, and the accent is another one. I.e., also visually it looks like one character, it actually consists of two. In Unicode terms, the letter is called a 'base character', while the accent is called 'combining diacritical mark'.

I have tried to show a normal black letter with an accent in different color above it (lets say red). Here is the code in VB:

'Box is the name of a RichTextBox

'Set the Text property to the letter 'a' + a line above it (called a 'macron')

Box.Text = a & ChrW(&H304)

'Select the macron, which is the second character (0 based)

Box.Select(1,1)

'change its color:

Box.SelectionColor = Color.Red

The code above doesn't work. The macron's color doesn't changes. On the other hand, when trying to select only the 'a' letter and changing its color, the macron's color changes as well:

Box.Select(0,1)

'change the letter color:

Box.SelectionColor = Color.Red

So I couldn't have a letter with one color, and its accent with another. I will add that I'm an Hebrew speaker, and when using the Hebrew version of Microsoft Word, one can easily changes the color of the Hebrew letters' marks (called 'Nikud') through the Word menus, i.e., give them different color from the letters.

If one doesn't now how to achieve this behavior through pure .Net code, and may know how to get it through win API calls, I appreciate any explanations, since I'm not familiar with that area.

EDIT:

Actually I have found a weird way, which I can't trust, to accomplish that partialy. I didn't mentioned it, because it looks like a 'positive bug' of the RichTextBox control. Since the control wasn't intended in advance to work that way, I can't perdict the consequences of such uses in terms of stability and compatibility at the end user system. Here it is:

'give the control a font I have decalred. It doesn't matter which font
'(as long as it supports the characters in use)
Box.Font = Lucida

'Add text
Box.Text = a & ChrW(&H304)

'Select the macron, which is the second character (0 based)
Box.Select(1,1)

'Here is the line that makes the difference:

Box.SelectionFont = Lucida
'*********************************************

'change its color:
Box.SelectionColor = Color.Red

As one can see, I have assigned to the selection (the macron) a font that it already have, so this line should have no affect. However, now the next line does change the color of the macron, leaving the letter color black. Strangely enough, This works in several font's sizes (14,16,26 and more) and doesn't work on others(12,18,24 and more). If one have any ideas about this I will be glad to hear.