RichTextBox EM_GETCHARFORMAT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWFyayBDb2xsYXJk?=

    #1

    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_GETCHARFORMA T 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.
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: RichTextBox EM_GETCHARFORMA T

    Mark,

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

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Mark Collard" <MarkCollard@di scussions.micro soft.comwrote in message
    news:06693DC1-5148-4C93-A7BE-D47EB2C6CBEC@mi crosoft.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_GETCHARFORMA T 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.

    Comment

    • =?Utf-8?B?TWFyayBDb2xsYXJk?=

      #3
      Re: RichTextBox EM_GETCHARFORMA T

      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_GETCHARFORMA T message.
      You just need to check the dwMask field to see which attributes are
      consistent throughout the selection.
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Mark Collard" <MarkCollard@di scussions.micro soft.comwrote in message
      news:06693DC1-5148-4C93-A7BE-D47EB2C6CBEC@mi crosoft.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_GETCHARFORMA T 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.
      >
      >
      >

      Comment

      Working...