更改文本框中的字体大小,但不适用于已存在的文本

时间:2017-01-01 06:09:44

标签: c# uwp windows-10-universal

如何更改TextBox的字体大小而不更改已在其中输入的所有文本的大小?

这就是我现在正在做的事情:

tbox.FontSize = 16;

但这会改变那里已有的所有文字。

1 个答案:

答案 0 :(得分:1)

使用richTextbox,你可以这样做,

string OldText = string.Empty;
private void textBox1_GotFocus(object sender, EventArgs e)
{
   OldText = textBox1.Text;
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
   string newText = textBox1.Text;     

}

然后,您可以通过查找长度来应用所选尺寸并应用尺寸

this.textBox1.SelectionStart = 10;
this.textBox1.SelectionLength = this.richTextBox1.Text.Length;
this.textBox1.SelectionFont = new System.Drawing.Font("Maiandra GD", 30);