How Do You Set Height or Width to Auto in Code?

You can set the Height or Width property of an element to Auto in code by using Double.NaN (Not a Number).

For example, in C#:

this.txtName.Width = Double.NaN;

And in VB .NET:

Me.txtName.Width = Double.Nan

© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 10/23/10
Comment or report problem with topic