我正在编写一个程序,用户应该能够在文本框中编写文本.我希望文本框能够自行调整大小,因此它适合内容.我尝试过以下方法:
private void textBoxTitle_TextChanged(object sender, TextChangedEventArgs e)
{
System.Drawing.Font myFont = new System.Drawing.Font("Verdana", 8);
System.Drawing.SizeF mySize = e.Graphics.MeasureString("This is a test", myFont);
this.textBoxTitle.Width = (int)Math.Round(mySize.Width, 0);
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,说Graphics不适用于TextChangedEventArgs.还有另一种方法可以调整文本框的大小吗?