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

淺唱寂寞╮ 提交于 2021-02-07 13:42:12

问题


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.


回答1:


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.




回答2:


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.)



来源:https://stackoverflow.com/questions/5691092/why-doesnt-autosize-property-in-windows-form-textbox-appear-in-intellisense

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!