luni, 25 august 2014

Autosize Control sized based on its text C# CilentSize

CilentSize

CilentSize gets or sets the height and width of the client area of the control.

Example:
Autosize TextBox width and height  based on its text.







C# Code:

 private void AutoSizeControl(Control control)
        {
            Graphics g = control.CreateGraphics();
            Size size = g.MeasureString(control.Text, control.Font).ToSize();
            control.ClientSize = new Size(size.Width+10 ,size.Height);
            g.Dispose();
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            AutoSizeControl(textBox1);  
        }

Niciun comentariu:

Trimiteți un comentariu