Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't AutoSize property in Windows Form TextBox appear in IntelliSense

According into the specs (http://msdn.microsoft.com/en-us/library/k63c05yf.aspx)

Textboxes in Windows Forms should have an autosize property.

And it actually doesn't break when you type in TextBox1.AutoSize = true. However, it doesn't seem to appear in the list of IntelliSense properties.

Why is this?

I have tried recompiling and it all compiles, but the textbox.autosize property never appears.

like image 654
Diskdrive Avatar asked Apr 17 '11 02:04

Diskdrive


People also ask

What is the use of AutoSize property in Visual Basic?

Use AutoSize to force a form to resize to fit its contents. A form does not automatically resize in the Visual Studio forms designer, regardless of the values of the AutoSize and AutoSizeMode properties. The form correctly resizes itself at run time according to the values of these two properties.

What is AutoSize?

Remarks. For controls with captions, the AutoSize property specifies whether the control automatically adjusts to display the entire caption. For controls without captions, this property specifies whether the control automatically adjusts to display the information stored in the control.


2 Answers

The AutoSize property for TextBox is always true, forced by the constructor. The property is hidden in the parent class (TextBoxBase) to avoid accidentally setting it to false. It has [Browsable(false)] to hide it in the property grid, [EditorBrowsable(EditorBrowsableState.Never)] to hide it in the IntelliSense popup window. You can change it however:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        textBox1.AutoSize = false;
        textBox1.Height += 10;
    }
}

Yes, doesn't look great. Now you know why it is hidden.

like image 162
Hans Passant Avatar answered Nov 15 '22 06:11

Hans Passant


The Control.AutoSize property (and its override in TextBoxBase) is declared with the following attribute:

[EditorBrowsable(EditorBrowsableState.Never)]

IntelliSense uses this property to decide not to show the property in the completions list.

(I don't know enough about Windows Forms to say why this property is marked not browsable.)

like image 20
James McNellis Avatar answered Nov 15 '22 08:11

James McNellis