none
Set superscript and subscript in formatted text in label .net

    Question

  • Dear honors,

     

    How to Set superscript and subscript in formatted text in label control or text box control in Windows application.


    Veera
    Friday, December 23, 2011 7:24 AM

Answers

  • Suppose you are developing a WPF application, and in TextBox, it does not support the edited text as "Superscript" or "Subscript". But RichText can (Note, there is a known issue in RichTextBox for the "Superscript" and "Subscript": http://social.msdn.microsoft.com/Forums/en/wpf/thread/f375a41b-2c36-4e51-8f6b-7ed828431412, so we should use the below solution for "Superscript" and "Subscript")

    
        <RichTextBox>
          <FlowDocument>
            <Paragraph FontFamily="Palatino Linotype">
              H
              <Run BaselineAlignment="Subscript" FontSize="9">2</Run> O
              Lenght=X
              <Run BaselineAlignment="Subscript" FontSize="9">2</Run> +Y
              <Run BaselineAlignment="Subscript" FontSize="9">2</Run>
            </Paragraph>
          </FlowDocument>
        </RichTextBox>
    
    


    And in WPF, we could use TextBox instead of the Label.

    -----------------------

     And in WinForm, RichTextBox still supports the RTF format, so you could use the RTF Superscript" or "Subscript" style in it. Or you could use RichTextBox.SelectionCharOffset property to change the style for the selected text in RichTextBox in Winform.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Monday, December 26, 2011 6:45 AM
    Moderator
  • Hi,

    Use this.

    <TextBlock FontSize="20">
                <Run>Normal Text</Run>
                <Run Typography.Variants="Superscript">Superscript Text</Run>
                <Run Typography.Variants="Subscript">Subscript Text</Run>
            </TextBlock>
    

    Thanks,

    Rajnikant

    Friday, December 23, 2011 7:30 AM

All replies

  • Hi,

    Use this.

    <TextBlock FontSize="20">
                <Run>Normal Text</Run>
                <Run Typography.Variants="Superscript">Superscript Text</Run>
                <Run Typography.Variants="Subscript">Subscript Text</Run>
            </TextBlock>
    

    Thanks,

    Rajnikant

    Friday, December 23, 2011 7:30 AM
  • Thanks for your reply...  How to use this in windows application Text box or Label Control?
    Veera
    Friday, December 23, 2011 7:33 AM
  • Hi,

    Are you using wpf or winform application ?

    Thanks,

    Rajnikant

    Friday, December 23, 2011 8:41 AM
  • Suppose you are developing a WPF application, and in TextBox, it does not support the edited text as "Superscript" or "Subscript". But RichText can (Note, there is a known issue in RichTextBox for the "Superscript" and "Subscript": http://social.msdn.microsoft.com/Forums/en/wpf/thread/f375a41b-2c36-4e51-8f6b-7ed828431412, so we should use the below solution for "Superscript" and "Subscript")

    
        <RichTextBox>
          <FlowDocument>
            <Paragraph FontFamily="Palatino Linotype">
              H
              <Run BaselineAlignment="Subscript" FontSize="9">2</Run> O
              Lenght=X
              <Run BaselineAlignment="Subscript" FontSize="9">2</Run> +Y
              <Run BaselineAlignment="Subscript" FontSize="9">2</Run>
            </Paragraph>
          </FlowDocument>
        </RichTextBox>
    
    


    And in WPF, we could use TextBox instead of the Label.

    -----------------------

     And in WinForm, RichTextBox still supports the RTF format, so you could use the RTF Superscript" or "Subscript" style in it. Or you could use RichTextBox.SelectionCharOffset property to change the style for the selected text in RichTextBox in Winform.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Monday, December 26, 2011 6:45 AM
    Moderator