none
Rich Text Control superscript and subscript.

    Question

  • The windows forms rich text control has the  property:- RichTextBox ..::. SelectionCharOffset Property which can be used to place characters in any vertical position above or below a base line. This property is not available as far as I can see in the WPF version of the control.  How can text be rendered raised or lowered in a similar way in WPF. I have  been able to get round this problem by using WIndows Forms integration in my WPF project but I would like to be able to raise and lower text with the WPF rich text control in a music notation program I am working on. If this is not possible, how can I persuade the WPF team to add the SelectionCharOffset Property  into the WPF Rich Text control.
    Tuesday, June 7, 2011 5:38 AM

Answers

  • Hi martin_taunton,

    I think Inline.BaselinAlignment property is what you are looking for.

    Here is a simple sample.

        <RichTextBox>
          <RichTextBox.Document>
            <FlowDocument>
              <Paragraph>
                <Run>X</Run>
                <Run BaselineAlignment="Superscript">2</Run>
              </Paragraph>
            </FlowDocument>
          </RichTextBox.Document>
        </RichTextBox>
    

    Please see this link for more details.

    Best regards,


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 9, 2011 9:12 AM
    Moderator

All replies

  • Hi martin_taunton,

    I think Inline.BaselinAlignment property is what you are looking for.

    Here is a simple sample.

        <RichTextBox>
          <RichTextBox.Document>
            <FlowDocument>
              <Paragraph>
                <Run>X</Run>
                <Run BaselineAlignment="Superscript">2</Run>
              </Paragraph>
            </FlowDocument>
          </RichTextBox.Document>
        </RichTextBox>
    

    Please see this link for more details.

    Best regards,


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 9, 2011 9:12 AM
    Moderator
  • Thank you Min for replying . Your solution will be helpful in situations where superscript and subscript amounts are needed with the default values. However , with the Windows Forms rich text control, the SelectionCharOffset property of the selected text enabled characters to be placed above or below the baseline in just about any position you liked within max and min limits of course (-2000 to +2000).  The function has these comments in the MSDN library

    RichTextBox ..::. SelectionCharOffset Property

    Public Property SelectionCharOffset As Integer
        Get
        Set

    The value of this property must be between -2000 and 2000.

     

    If this property is set to zero, the text appears on the baseline. If it is a positive number, the number specifies the number of pixels by which to raise the text selection above the baseline. If it is a negative number, this number specifies the number of pixels by which to subscript the text selection. You can use this property to specify text as superscript or subscript.

    I found this function extremely useful in a music notation program I worked on for placing notes in their relative vertical positions.  I just wish I could find a way of acheiving the same result with the WPF rich text control without having to resort to forms integration, although I suppose thare is no real problem in doing so.

    Thanks again and I would be interested in any other suggestion about this.

     

    Martin


    martin_taunton
    Thursday, June 9, 2011 4:55 PM