RichTextBox EM_GETCHARFORMAT


M

Mark Collard

I'm currently writing an application that has a RichTextBox and a toolbar
which includes the following toolbar buttons:
- Font
- Font Size
- Bold
- Italic
- Underline

I want the toolbox buttons to act the same as the ones in Word. i.e. When
you select text that has different Fonts the Font toolbar button (combo box)
is blanked, and when you select text that has different Font Sizes the Font
Size toolbar button (combo box) is blanked.

The RichTextBox control has a property called SelectionFont. The
SelectionFont property returns null if the selected text contains different
fonts, which is fine if I just wanted to update the Font toolbar button
(combo box), but I also want to update the Font Size, Bold, Italic and
Underline buttons. So I looked for an API solution and found that using the
EM_GETCHARFORMAT message with the SendMessage API would return me the
selected Font, Font Size, Bold, Italic and Underline settings, but it doesn't
tell me when multiple Fonts or Font Sizes have been selected. In these cases
it seems to return the Font and Font Size values of where the cursor is in
the RichTextBox.

How can I workout if the selected text in the RichTextBox control contains
multiple fonts, but the same font size?
And how can I workout if the selected text in the RichTextBox control
contains multiple font sizes, but the same font?

Thank you for your help.
 
Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

Mark,

You can still call SendMessage, passing the EM_GETCHARFORMAT message.
You just need to check the dwMask field to see which attributes are
consistent throughout the selection.
 
Ad

Advertisements

M

Mark Collard

Nicholas,

Can you please show me an example on how I would check the dwMask field to
see which attributes are consistent throughout the selection.

Thank you.

Regards
Mark

Nicholas Paldino said:
Mark,

You can still call SendMessage, passing the EM_GETCHARFORMAT message.
You just need to check the dwMask field to see which attributes are
consistent throughout the selection.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark Collard said:
I'm currently writing an application that has a RichTextBox and a toolbar
which includes the following toolbar buttons:
- Font
- Font Size
- Bold
- Italic
- Underline

I want the toolbox buttons to act the same as the ones in Word. i.e. When
you select text that has different Fonts the Font toolbar button (combo
box)
is blanked, and when you select text that has different Font Sizes the
Font
Size toolbar button (combo box) is blanked.

The RichTextBox control has a property called SelectionFont. The
SelectionFont property returns null if the selected text contains
different
fonts, which is fine if I just wanted to update the Font toolbar button
(combo box), but I also want to update the Font Size, Bold, Italic and
Underline buttons. So I looked for an API solution and found that using
the
EM_GETCHARFORMAT message with the SendMessage API would return me the
selected Font, Font Size, Bold, Italic and Underline settings, but it
doesn't
tell me when multiple Fonts or Font Sizes have been selected. In these
cases
it seems to return the Font and Font Size values of where the cursor is in
the RichTextBox.

How can I workout if the selected text in the RichTextBox control contains
multiple fonts, but the same font size?
And how can I workout if the selected text in the RichTextBox control
contains multiple font sizes, but the same font?

Thank you for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Richtextbox (RTB) 2
Richtextbox 1
Formatting 'text' in RichTextBox ... 2
Font Problem 1
Font Issues 1
Formatting text in a RichTextBox in WindowsForm 3
Login control 1
printing Richtextbox 2

Top