By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,497 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,497 IT Pros & Developers. It's quick & easy.

Equvalent of "Shadows" in VB.Net?

P: n/a
Hi,

I'm trying to hide an event of my custom usercontrol derived control,
something like "Shadows" in VB.Net, but although the event is hidden from
PropertyGrid, from CodeEditor I can still see/reach it. I use this code :

[EditorBrowsable(EditorBrowsableState.Never)]

[Browsable(false)]

new public event EventHandler BackColorChanged;

Does anybody knows a solution for this?

Thanks in advance,

Özden
Nov 16 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Try marking the event as protected or internal.

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
| Hi,
|
| I'm trying to hide an event of my custom usercontrol derived control,
| something like "Shadows" in VB.Net, but although the event is hidden from
| PropertyGrid, from CodeEditor I can still see/reach it. I use this code :
|
| [EditorBrowsable(EditorBrowsableState.Never)]
|
| [Browsable(false)]
|
| new public event EventHandler BackColorChanged;
|
| Does anybody knows a solution for this?
|
| Thanks in advance,
|
| Özden
|
|
Nov 16 '05 #2

P: n/a
Dear Kyril,

Thanks for the suggestion but I already tried it at got no success...

Any other suggestion?

Thanks again..

Özden

"Kyril Magnos" <ky**********@yahoo.com> wrote in message
news:O2**************@tk2msftngp13.phx.gbl...
Try marking the event as protected or internal.

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
| Hi,
|
| I'm trying to hide an event of my custom usercontrol derived control,
| something like "Shadows" in VB.Net, but although the event is hidden from | PropertyGrid, from CodeEditor I can still see/reach it. I use this code : |
| [EditorBrowsable(EditorBrowsableState.Never)]
|
| [Browsable(false)]
|
| new public event EventHandler BackColorChanged;
|
| Does anybody knows a solution for this?
|
| Thanks in advance,
|
| Özden
|
|

Nov 16 '05 #3

P: n/a
Hmm, short of marking the event private, no.

In what scope will this event be used? It is something that will only be
used internally by the control? Or, will consumers of the control be able to
register for the event?

--
HTH

Kyril

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:eC*************@tk2msftngp13.phx.gbl...
| Dear Kyril,
|
| Thanks for the suggestion but I already tried it at got no success...
|
| Any other suggestion?
|
| Thanks again..
|
| Özden
|
| "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| news:O2**************@tk2msftngp13.phx.gbl...
| > Try marking the event as protected or internal.
| >
| > --
| > HTH
| >
| > Kyril Magnos
| > "I'm not a developer anymore, I'm a software engineer now!" :-)
| >
| > "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > news:uZ**************@TK2MSFTNGP10.phx.gbl...
| > | Hi,
| > |
| > | I'm trying to hide an event of my custom usercontrol derived control,
| > | something like "Shadows" in VB.Net, but although the event is hidden
| from
| > | PropertyGrid, from CodeEditor I can still see/reach it. I use this
code
| :
| > |
| > | [EditorBrowsable(EditorBrowsableState.Never)]
| > |
| > | [Browsable(false)]
| > |
| > | new public event EventHandler BackColorChanged;
| > |
| > | Does anybody knows a solution for this?
| > |
| > | Thanks in advance,
| > |
| > | Özden
| > |
| > |
| >
| >
|
|
Nov 16 '05 #4

P: n/a
Dear Kyril,

Yes, events are going to be used internally and won't be exposed to the
developer...Developer neither will see it in PropertyGrid nor will be able
to register it via code...

"Shadows" works in VB.Net but I couldn't find the same in C#...:(

Özden

"Kyril Magnos" <ky**********@yahoo.com> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
Hmm, short of marking the event private, no.

In what scope will this event be used? It is something that will only be
used internally by the control? Or, will consumers of the control be able to register for the event?

--
HTH

Kyril

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:eC*************@tk2msftngp13.phx.gbl...
| Dear Kyril,
|
| Thanks for the suggestion but I already tried it at got no success...
|
| Any other suggestion?
|
| Thanks again..
|
| Özden
|
| "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| news:O2**************@tk2msftngp13.phx.gbl...
| > Try marking the event as protected or internal.
| >
| > --
| > HTH
| >
| > Kyril Magnos
| > "I'm not a developer anymore, I'm a software engineer now!" :-)
| >
| > "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > news:uZ**************@TK2MSFTNGP10.phx.gbl...
| > | Hi,
| > |
| > | I'm trying to hide an event of my custom usercontrol derived control, | > | something like "Shadows" in VB.Net, but although the event is hidden
| from
| > | PropertyGrid, from CodeEditor I can still see/reach it. I use this
code
| :
| > |
| > | [EditorBrowsable(EditorBrowsableState.Never)]
| > |
| > | [Browsable(false)]
| > |
| > | new public event EventHandler BackColorChanged;
| > |
| > | Does anybody knows a solution for this?
| > |
| > | Thanks in advance,
| > |
| > | Özden
| > |
| > |
| >
| >
|
|

Nov 16 '05 #5

P: n/a
I think "new" in C# is the equivivalent of "Shadows" in VB.

/Chris


"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
Hi,

I'm trying to hide an event of my custom usercontrol derived control,
something like "Shadows" in VB.Net, but although the event is hidden from
PropertyGrid, from CodeEditor I can still see/reach it. I use this code :

[EditorBrowsable(EditorBrowsableState.Never)]

[Browsable(false)]

new public event EventHandler BackColorChanged;

Does anybody knows a solution for this?

Thanks in advance,

Özden

Nov 16 '05 #6

P: n/a
Hi Özden,

Then you would want to mark your event as private. That will allow access
internally to the class itself but will not allow access to it from
consumers or other outside components.

//this event is only seen from this class.
private event EventHandler myEvent;

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...
| Dear Kyril,
|
| Yes, events are going to be used internally and won't be exposed to the
| developer...Developer neither will see it in PropertyGrid nor will be able
| to register it via code...
|
| "Shadows" works in VB.Net but I couldn't find the same in C#...:(
|
| Özden
|
| "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| news:OQ**************@tk2msftngp13.phx.gbl...
| > Hmm, short of marking the event private, no.
| >
| > In what scope will this event be used? It is something that will only be
| > used internally by the control? Or, will consumers of the control be
able
| to
| > register for the event?
| >
| > --
| > HTH
| >
| > Kyril
| >
| > "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > news:eC*************@tk2msftngp13.phx.gbl...
| > | Dear Kyril,
| > |
| > | Thanks for the suggestion but I already tried it at got no success...
| > |
| > | Any other suggestion?
| > |
| > | Thanks again..
| > |
| > | Özden
| > |
| > | "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| > | news:O2**************@tk2msftngp13.phx.gbl...
| > | > Try marking the event as protected or internal.
| > | >
| > | > --
| > | > HTH
| > | >
| > | > Kyril Magnos
| > | > "I'm not a developer anymore, I'm a software engineer now!" :-)
| > | >
| > | > "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > | > news:uZ**************@TK2MSFTNGP10.phx.gbl...
| > | > | Hi,
| > | > |
| > | > | I'm trying to hide an event of my custom usercontrol derived
| control,
| > | > | something like "Shadows" in VB.Net, but although the event is
hidden
| > | from
| > | > | PropertyGrid, from CodeEditor I can still see/reach it. I use this
| > code
| > | :
| > | > |
| > | > | [EditorBrowsable(EditorBrowsableState.Never)]
| > | > |
| > | > | [Browsable(false)]
| > | > |
| > | > | new public event EventHandler BackColorChanged;
| > | > |
| > | > | Does anybody knows a solution for this?
| > | > |
| > | > | Thanks in advance,
| > | > |
| > | > | Özden
| > | > |
| > | > |
| > | >
| > | >
| > |
| > |
| >
| >
|
|
Nov 16 '05 #7

P: n/a
Yes, the new keyword is the equivalent of Shadows in VB.NET.

--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

"Christoffer Skjoldborg" <firstnameATlastnameDOT.biz> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
|I think "new" in C# is the equivivalent of "Shadows" in VB.
|
| /Chris
|
|
|
|
| "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| news:uZ**************@TK2MSFTNGP10.phx.gbl...
| > Hi,
| >
| > I'm trying to hide an event of my custom usercontrol derived control,
| > something like "Shadows" in VB.Net, but although the event is hidden
from
| > PropertyGrid, from CodeEditor I can still see/reach it. I use this code
:
| >
| > [EditorBrowsable(EditorBrowsableState.Never)]
| >
| > [Browsable(false)]
| >
| > new public event EventHandler BackColorChanged;
| >
| > Does anybody knows a solution for this?
| >
| > Thanks in advance,
| >
| > Özden
| >
| >
|
|
Nov 16 '05 #8

P: n/a
Hi Özden,

I did some research and came up with this. The BackColorChanged event is
inherited from UserControl and as such cannot be hidden from the code
internally in C#. One of the facts of life and inheritance. Now, while you
can hide it from the PropertyGrid by using Attributes, you will not be able
to hide it from code. Unfortunately, VB and C# do inheritance a bit
differently. The Shadows keyword in VB allows you to hide a base class
member by defining a new member that can have a different access level,
return type, and parameter signature. In other words, only the name remains
the same but the member itself may be completely different. Base class
members hidden in C# using the "new" keyword can only redefine their access
level and return type. The parameter signature must remain the same, or the
method is treated as an overload. This is why you cannot hide it completely
from code. But, I have a solution for you. While you cannot hide it, you can
override the OnBackColorChanged() method like so:

protected override void OnBackColorChanged(EventArgs e)
{
base.OnBackColorChanged (e);
throw new NotImplementedException("This event is unavailable");
//I just put this in, you can put whatever you want here...
}

So that even if the consumer registers for the event, they will not be able
to anything with it.
--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
|I know that "new" keyword is the equal/nearest functional in C# for
| "Shadows" in VB.Net but I couldn't get it work like in "Shadows"...
|
| I've attached two sample "usercontrol" files...In VB.Net, I can hide
| "BackColorChanged" with "Shadows" but in C#, even it hides it from the
| PropertyGrid, I can still see/reach it via code after I use "new"...
|
| Any help will be appreciated...
|
| Özden
|
| "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| news:%2****************@TK2MSFTNGP10.phx.gbl...
| > Yes, the new keyword is the equivalent of Shadows in VB.NET.
| >
| > --
| > HTH
| >
| > Kyril Magnos
| > "I'm not a developer anymore, I'm a software engineer now!" :-)
| >
| > "Christoffer Skjoldborg" <firstnameATlastnameDOT.biz> wrote in message
| > news:Os**************@TK2MSFTNGP11.phx.gbl...
| > |I think "new" in C# is the equivivalent of "Shadows" in VB.
| > |
| > | /Chris
| > |
| > |
| > |
| > |
| > | "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > | news:uZ**************@TK2MSFTNGP10.phx.gbl...
| > | > Hi,
| > | >
| > | > I'm trying to hide an event of my custom usercontrol derived
control,
| > | > something like "Shadows" in VB.Net, but although the event is hidden
| > from
| > | > PropertyGrid, from CodeEditor I can still see/reach it. I use this
| code
| > :
| > | >
| > | > [EditorBrowsable(EditorBrowsableState.Never)]
| > | >
| > | > [Browsable(false)]
| > | >
| > | > new public event EventHandler BackColorChanged;
| > | >
| > | > Does anybody knows a solution for this?
| > | >
| > | > Thanks in advance,
| > | >
| > | > Özden
| > | >
| > | >
| > |
| > |
| >
| >
|
|
|
Nov 16 '05 #9

P: n/a
Dear Kyril,

Thank you for your great effort on solving my problem...

Normally I don't care whether the events will work or not but it was
essential for me to hide the events as those events normally doesn't have
anything to do with my control, in a correct way, my control is for a
specific purpose and I didn't want to make it available for a generic usage
(Some technical and commercial reasons lies on this) so I wanted to hide the
events...

Anyway, if we can't do it, nothing else can be done...

I again want to thank you for your personal attention...

Best Wishes,

Özden Irmak

"Kyril Magnos" <ky**********@yahoo.com> wrote in message
news:u2**************@TK2MSFTNGP11.phx.gbl...
Hi Özden,

I did some research and came up with this. The BackColorChanged event is
inherited from UserControl and as such cannot be hidden from the code
internally in C#. One of the facts of life and inheritance. Now, while you
can hide it from the PropertyGrid by using Attributes, you will not be able to hide it from code. Unfortunately, VB and C# do inheritance a bit
differently. The Shadows keyword in VB allows you to hide a base class
member by defining a new member that can have a different access level,
return type, and parameter signature. In other words, only the name remains the same but the member itself may be completely different. Base class
members hidden in C# using the "new" keyword can only redefine their access level and return type. The parameter signature must remain the same, or the method is treated as an overload. This is why you cannot hide it completely from code. But, I have a solution for you. While you cannot hide it, you can override the OnBackColorChanged() method like so:

protected override void OnBackColorChanged(EventArgs e)
{
base.OnBackColorChanged (e);
throw new NotImplementedException("This event is unavailable");
//I just put this in, you can put whatever you want here...
}

So that even if the consumer registers for the event, they will not be able to anything with it.
--
HTH

Kyril Magnos
"I'm not a developer anymore, I'm a software engineer now!" :-)

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
|I know that "new" keyword is the equal/nearest functional in C# for
| "Shadows" in VB.Net but I couldn't get it work like in "Shadows"...
|
| I've attached two sample "usercontrol" files...In VB.Net, I can hide
| "BackColorChanged" with "Shadows" but in C#, even it hides it from the
| PropertyGrid, I can still see/reach it via code after I use "new"...
|
| Any help will be appreciated...
|
| Özden
|
| "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| news:%2****************@TK2MSFTNGP10.phx.gbl...
| > Yes, the new keyword is the equivalent of Shadows in VB.NET.
| >
| > --
| > HTH
| >
| > Kyril Magnos
| > "I'm not a developer anymore, I'm a software engineer now!" :-)
| >
| > "Christoffer Skjoldborg" <firstnameATlastnameDOT.biz> wrote in message
| > news:Os**************@TK2MSFTNGP11.phx.gbl...
| > |I think "new" in C# is the equivivalent of "Shadows" in VB.
| > |
| > | /Chris
| > |
| > |
| > |
| > |
| > | "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > | news:uZ**************@TK2MSFTNGP10.phx.gbl...
| > | > Hi,
| > | >
| > | > I'm trying to hide an event of my custom usercontrol derived
control,
| > | > something like "Shadows" in VB.Net, but although the event is hidden | > from
| > | > PropertyGrid, from CodeEditor I can still see/reach it. I use this
| code
| > :
| > | >
| > | > [EditorBrowsable(EditorBrowsableState.Never)]
| > | >
| > | > [Browsable(false)]
| > | >
| > | > new public event EventHandler BackColorChanged;
| > | >
| > | > Does anybody knows a solution for this?
| > | >
| > | > Thanks in advance,
| > | >
| > | > Özden
| > | >
| > | >
| > |
| > |
| >
| >
|
|
|

Nov 16 '05 #10

P: n/a
Not a problem at all. Best of luck to you. :-)

--
Kyril Magnos

"Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
news:eF*************@TK2MSFTNGP11.phx.gbl...
| Dear Kyril,
|
| Thank you for your great effort on solving my problem...
|
| Normally I don't care whether the events will work or not but it was
| essential for me to hide the events as those events normally doesn't have
| anything to do with my control, in a correct way, my control is for a
| specific purpose and I didn't want to make it available for a generic
usage
| (Some technical and commercial reasons lies on this) so I wanted to hide
the
| events...
|
| Anyway, if we can't do it, nothing else can be done...
|
| I again want to thank you for your personal attention...
|
| Best Wishes,
|
| Özden Irmak
|
| "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| news:u2**************@TK2MSFTNGP11.phx.gbl...
| > Hi Özden,
| >
| > I did some research and came up with this. The BackColorChanged event is
| > inherited from UserControl and as such cannot be hidden from the code
| > internally in C#. One of the facts of life and inheritance. Now, while
you
| > can hide it from the PropertyGrid by using Attributes, you will not be
| able
| > to hide it from code. Unfortunately, VB and C# do inheritance a bit
| > differently. The Shadows keyword in VB allows you to hide a base class
| > member by defining a new member that can have a different access level,
| > return type, and parameter signature. In other words, only the name
| remains
| > the same but the member itself may be completely different. Base class
| > members hidden in C# using the "new" keyword can only redefine their
| access
| > level and return type. The parameter signature must remain the same, or
| the
| > method is treated as an overload. This is why you cannot hide it
| completely
| > from code. But, I have a solution for you. While you cannot hide it, you
| can
| > override the OnBackColorChanged() method like so:
| >
| > protected override void OnBackColorChanged(EventArgs e)
| > {
| > base.OnBackColorChanged (e);
| > throw new NotImplementedException("This event is unavailable");
| > //I just put this in, you can put whatever you want here...
| > }
| >
| > So that even if the consumer registers for the event, they will not be
| able
| > to anything with it.
| > --
| > HTH
| >
| > Kyril Magnos
| > "I'm not a developer anymore, I'm a software engineer now!" :-)
| >
| > "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > news:e2**************@tk2msftngp13.phx.gbl...
| > |I know that "new" keyword is the equal/nearest functional in C# for
| > | "Shadows" in VB.Net but I couldn't get it work like in "Shadows"...
| > |
| > | I've attached two sample "usercontrol" files...In VB.Net, I can hide
| > | "BackColorChanged" with "Shadows" but in C#, even it hides it from the
| > | PropertyGrid, I can still see/reach it via code after I use "new"...
| > |
| > | Any help will be appreciated...
| > |
| > | Özden
| > |
| > | "Kyril Magnos" <ky**********@yahoo.com> wrote in message
| > | news:%2****************@TK2MSFTNGP10.phx.gbl...
| > | > Yes, the new keyword is the equivalent of Shadows in VB.NET.
| > | >
| > | > --
| > | > HTH
| > | >
| > | > Kyril Magnos
| > | > "I'm not a developer anymore, I'm a software engineer now!" :-)
| > | >
| > | > "Christoffer Skjoldborg" <firstnameATlastnameDOT.biz> wrote in
message
| > | > news:Os**************@TK2MSFTNGP11.phx.gbl...
| > | > |I think "new" in C# is the equivivalent of "Shadows" in VB.
| > | > |
| > | > | /Chris
| > | > |
| > | > |
| > | > |
| > | > |
| > | > | "Özden Irmak" <ozdenirmakatisnetdotnetdottr> wrote in message
| > | > | news:uZ**************@TK2MSFTNGP10.phx.gbl...
| > | > | > Hi,
| > | > | >
| > | > | > I'm trying to hide an event of my custom usercontrol derived
| > control,
| > | > | > something like "Shadows" in VB.Net, but although the event is
| hidden
| > | > from
| > | > | > PropertyGrid, from CodeEditor I can still see/reach it. I use
this
| > | code
| > | > :
| > | > | >
| > | > | > [EditorBrowsable(EditorBrowsableState.Never)]
| > | > | >
| > | > | > [Browsable(false)]
| > | > | >
| > | > | > new public event EventHandler BackColorChanged;
| > | > | >
| > | > | > Does anybody knows a solution for this?
| > | > | >
| > | > | > Thanks in advance,
| > | > | >
| > | > | > Özden
| > | > | >
| > | > | >
| > | > |
| > | > |
| > | >
| > | >
| > |
| > |
| > |
| >
| >
|
|
Nov 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.