查找和使用隐藏的属性(例如DisplayRectangle) [英] Finding and using hidden properties(such as DisplayRectangle)

查看:280
本文介绍了查找和使用隐藏的属性(例如DisplayRectangle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多代码示例中,我发现正在使用的Control对象的DisplayRectangle属性. 但是,此属性不会出现在智能感知"弹出窗口中,也不会突出显示任何语法,但是可以按预期进行编译和工作.

In many code examples I have found the DisplayRectangle property of a Control object being used. However this property does not appear in the intellisense popup, neither does it get any syntax highlighting, but it does compile and work as expected.

我应该使用这种财产吗?

Should I use this kind of Property?

我如何找到更多它们,它们是否可以在智能感知中被激活?

How can I find out about more of them, can they be activated in intellisense?

更新/澄清:我现在发现它似乎取决于哪个控件.以下代码会编译:

Update/Clarification: I have now found out that it does seem that it depends on which control. The following code does compile:

        Control c = sender as Control;
        Form f = sender as Form;
        PictureBox p = sender as PictureBox;
        Console.Write(c.DisplayRectangle); // No Intellisense
        Console.Write(f.DisplayRectangle); // Intellisense
        Console.Write(p.DisplayRectangle); // No Intellisense

我的问题是有关PictureBox的DisplayRectangle或一般的控件.

My question was about the DisplayRectangle for PictureBox, or Controls in general.

推荐答案

这是属性的声明:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
[Browsable(false)]
[SRDescription("ControlDisplayRectangleDescr")]
public virtual Rectangle DisplayRectangle
{
    get
    {
        return new Rectangle(0x0, 0x0, this.clientWidth, this.clientHeight);
    }
}

从[Browsable]开始,该属性可确保该属性不会出现在属性"窗口中.这是有道理的,因为它是运行时属性,并且没有设置程序.这也是与[DesignerSerializationVisibility]的关联,它确保不会将属性值写入InitializeComponent()方法. [SRDescription]用于本地化.

Starting with [Browsable], that attribute ensures that the property doesn't show up in the Properties window. Which makes sense because it is a runtime property and there is no setter. That's also the relevance to [DesignerSerializationVisibility], it ensures that the property value doesn't get written to the InitializeComponent() method. [SRDescription] is for localization.

[EditorBrowsable]与您的问题有关.使用EditorBrowsableState.Advanced可确保仅当编辑器在显示高级IntelliSense信息"模式下运行时,IntelliSense才会显示该属性.我知道使用此功能的唯一IDE是VB.NET,其IntelliSense弹出窗口具有所有"选项卡,但默认为通用".但是不是C#IDE,而是您用来标记问题的语言.

is relevant to your question. Using EditorBrowsableState.Advanced ensures that IntelliSense will only display the property if the editor is operating in 'Show advanced IntelliSense info' mode. The only IDE that I know that uses this feature is VB.NET, its IntelliSense popup window has an "All" tab but defaults to "Common". But not the C# IDE, the language you tagged your question with.

我不得不猜测您实际上是在VB.NET而不是C#中进行编程.点击弹出窗口上的全部标签.

I have to guess that you are actually programming in VB.NET, not C#. Click the All tab on the popup.

这篇关于查找和使用隐藏的属性(例如DisplayRectangle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆