views:

74

answers:

2

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

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

A: 

Instead can you modify the line slightely to : (c as Control).DisplayRectangle . In this style just after closing brace, the intellisense should show the property. Is that solve your problem ?

Siva Gopal
Sorry my syntax was not correct c# I only wanted to make clear that it was an instance property, not a class property.
phq
+5  A: 

This is the declaration of the property:

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

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

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

Hans Passant
So visual-studio-2008 on a c# project does not show advanced intellisense info? Should I then use that property in a c# project? - Sorry it does show but not always.
phq
The C# IDE *does* show this property. There is no reason not to use it. I cannot guess at "not always", other than that you don't actually have a Control reference. Update your question with sample code that reproduces your problem.
Hans Passant
Now I found out it did show, sometimes. See update in the question.
phq
I get no repro for this, the property shows up consistently when I use the code in your snippet. Tested in VS2008, SP1.
Hans Passant