首页 文章

WPF(C#)中TextBox中不同的字体大小和方向

提问于
浏览
2

我有一个像这样的文本框

<TextBox x:Name="SA1" Grid.Row="1" Grid.Column="1" TextAlignment="Center"/>

我需要一个单/两位数字,以较低的字体大小放置在此文本框的左上角 . 其余的文本必须在文本框的中心(vert和hor)中以更大的字体大小设置样式 .

如何在C#中以编程方式执行此操作 . 与我们在填字游戏中看到的相似 .

1 回答

  • 2

    由于您已经在Grid中使用了TextBox,因此您只需将TextBlock添加到将在其上呈现的同一单元格中 . 您可以使用HorizontalAlignment和VerticalAlignment对齐TextBlock,并可以单独设置其上的字体大小 .

    <TextBox x:Name="SA1" Grid.Row="1" Grid.Column="1"
        TextAlignment="Center" VerticalAlignment="Center" FontSize="20"/>
    <TextBlock Grid.Row="1" Grid.Column="1"
        HorizontalAlignment="Left" VerticalAlignment="Top" Text="10" FontSize="8"/>
    

相关问题