TextBox根据文本长度自动扩大宽度

        /// 
        ///  TextBox根据文本长度自动扩大宽度
        /// 
        /// 
        /// 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Graphics g = this.textBox1.CreateGraphics();
            System.Drawing.SizeF s = g.MeasureString(this.textBox1.Text, this.textBox1.Font);
            this.textBox1.Width = (int)s.Width + 3;
        }

 

你可能感兴趣的:(TextBox根据文本长度自动扩大宽度)