Browsable Attribute For Events

F

Flix

When I extend a Control and I want to hide a property at design time, I do:

public class MyButton : Button
{
[Browsable(false)]
public new System.String Text
{
get{return base.Text;}
set{base.Text=value;}
}
}
(Note that I could have used "override" instead of "new", but with inherited
properties (like "Enabled") only "new" can be used)

I've tried to do the same to hide some events from the design time property
grid:

public class MyButton : Button
{
[Browsable(false)]
public new event System.EventHandler Click
{
add{base.Click+=value;}
remove{base.Click-=value;}
}
}

But it doesn't seem to work (the event is still visible). Why?
 
N

Nicholas Paldino [.NET/C# MVP]

Flix,

Try attaching the browsable attribute to the field instead of the event,
like so:


public class MyButton : Button
{
[field:Browsable(false)]
public new System.String Text
{
get{return base.Text;}
set{base.Text=value;}
}
}

I'm not sure that this will work, but it's worth a try.

Hope this helps.
 
F

Flix

Nicholas Paldino said:
Try attaching the browsable attribute to the field instead of the
event, like so:


public class MyButton : Button
{
[field:Browsable(false)]
public new System.String Text
{
get{return base.Text;}
set{base.Text=value;}
}
}

Well: I can't find any namespace in which "field" is defined.

But the code for properties works. It's with events that the Browsable
Attribute doesn't seem to work.
 
N

Nicholas Paldino [.NET/C# MVP]

Flix,

field is not a namespace. Its an indicator to the attribute to give it
an idea of where to apply it. Instead of the event, you are applying it to
the delegate field that the event handlers are stored in. It's the same as
the assembly: prefix you see in the assembly.cs file that is generated for
you with new projects.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Flix said:
Nicholas Paldino said:
Try attaching the browsable attribute to the field instead of the
event, like so:


public class MyButton : Button
{
[field:Browsable(false)]
public new System.String Text
{
get{return base.Text;}
set{base.Text=value;}
}
}

Well: I can't find any namespace in which "field" is defined.

But the code for properties works. It's with events that the Browsable
Attribute doesn't seem to work.
 
F

Flix

Nicholas Paldino said:
Flix,

field is not a namespace. Its an indicator to the attribute to give it
an idea of where to apply it. Instead of the event, you are applying it
to the delegate field that the event handlers are stored in. It's the
same as the assembly: prefix you see in the assembly.cs file that is
generated for you with new projects.
Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top