469,957 Members | 2,705 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,957 developers. It's quick & easy.

RichTextBox EM_GETCHARFORMAT

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.
Nov 28 '07 #1
2 3388
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]
- mv*@spam.guard.caspershouse.com

"Mark Collard" <Ma*********@discussions.microsoft.comwrote in message
news:06**********************************@microsof t.com...
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.

Nov 28 '07 #2
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Mark Collard" <Ma*********@discussions.microsoft.comwrote in message
news:06**********************************@microsof t.com...
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.


Nov 29 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by nouno | last post: by
8 posts views Thread by Martin Horn | last post: by
9 posts views Thread by James Wong | last post: by
3 posts views Thread by michael sorens | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.