Format text inside a label in a Windows application

I want to add text to my label as: area (m ^ 2), but 2 should be able to m.

Is it possible to do this in .NET?

+5
source share
5 answers

enter image description here

<Label Content="2 power of 3 => 3 &#x00B2; " />

instead U+00B2i wrote&#x00B2;

But if you want to write it with C # code, you must use the first format

label.Content = "\u00B2";
+3
source

Use the superscript 2 character ²(unicode U + 00B2).

+1
source

, Inlines TextBlock:

<TextBlock>
    <TextBlock.Inlines>
        <Run Text="area (m"/>
        <Run Text="2" BaselineAlignment="Superscript"/>
        <Run Text=")"/>
    </TextBlock.Inlines>
</TextBlock>

FontSize .

, TextBlock Label Content:

<Label>
    <TextBlock>
        <TextBlock.Inlines>
            <Run Text="area (m"/>
            <Run Text="2" BaselineAlignment="Superscript"/>
            <Run Text=")"/>
        </TextBlock.Inlines>
    </TextBlock>
</Label>
+1

WPF :

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <FlowDocumentReader>
        <FlowDocument>
            <Paragraph>
                <Span>number</Span>
                <Span BaselineAlignment="Superscript">2</Span>
                <Span>number</Span>
                <Span BaselineAlignment="Subscript">indexed2</Span>
            </Paragraph>
        </FlowDocument>
    </FlowDocumentReader>
</Grid>

which gives you the result in the image below:

enter image description here

0
source

It’s best to add a second label to hold “2”, and a place above label 1 to make it feel like a square.

-1
source

All Articles