我有以下代码
TextBox1.Text = "Two of the peak human experiences are "
TextBox1.Text = TextBox1.Text & "good food and classical music."
TextBox1.FontSize = "16"
它在同一文本框中显示两行。如何更改每行文本的字体大小并将它们显示在同一文本框中?
答案 0 :(得分:3)
请改用richtextbox。
richTextBox1.SelectionFont = new Font("Arial", 12, FontStyle.Bold);
richTextBox1.AppendText("Two of the peak human experiences are");
richTextBox1.SelectionFont = new Font("Tahoma", 16, FontStyle.Bold);
richTextBox1.AppendText("good food and classical music");
答案 1 :(得分:0)
您无法使用TextBox执行此操作,但可以使用RichTextBox:
<RichTextBox>
<RichTextBox.Resources>
<Style x:Key="Bigger">
<Setter Property="FontSize" Value="16"/>
</Style>
</RichTextBox.Resources>
<FlowDocument>
<Paragraph>
This is the first paragraph.
</Paragraph>
<Paragraph Style={StaticResource Bigger}>
This is the second paragraph.
</Paragraph>
</FlowDocument>
</RichTextBox>