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

Making events Private in Inheirted Controls

P: n/a
I have a control that inheirts from "Panel". I want to prevent the user from
having access to the MoueUp event. I tried making a sub in my control that
handles MyBase.MouseUp but still this event shows up as an event the user can
use. Is there anyway to prevent users of this control from getting access to
events such as MouseUp. Thanks.
--
Dennis in Houston
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Yes, I understand and it doesn't take any action even thought the user has
programmed some stuff for the MouseUp event. However, I wanted to actually
hide the mouseup event from the user in the design mode to where he couldn't
select the MouseUp event from the Declarations section so I wouldn't have to
explain this in the documentation.

"Richard Myers" wrote:
Gidday Dennis

I am assuming you are talking about a control that you directly inheriting from the Panel control
rather than a composite user control with a Panel on it?

In this case you need to sink the event by Overriding the OnMouseUp method of the base class in this
case the Panel. You shouldn'd Handle events raised by a base class when you are inheriting from it.
Its sloppy. By handling the event all you are doing is registering a method to observe that event
you are not taking control of it. Its kinda like subclassing a cloud. You want to subclass a cloud
so that you dont get wet if it rains. By Handling the event all you've done is pop an umbrella
above YOUR head but all the rest of us are still going to get wet becuase Handling this event for
you is not propagating the same protection to all of us.

What you need to do is turn off the rain and then no one gets wet regardless of "weather" they have
an umbrella or not. To do that you
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
' Do thing
End Sub

This event is now sunk. If on the hand you also wanted to do something with the base class you would

Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseUp(e)
MyStuffMethod()
End Sub

This would capture the base class event and perform you custom action and then spin the event out to
all who had registered for it. If you wanted to perform a custom action before turning it off then
you just wuldn;t MyBase.nMouseUp(e)
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
MyStuffMethod()
End Sub

This would perform your custom action before sinking the event. Note that implementers of your class
can still register for the event;its just that nothing will happen;if its sunk it will never be
caught by a Hnaldes clause. So you need to document this clearly.

hth
Richard
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
I have a control that inheirts from "Panel". I want to prevent the user from
having access to the MoueUp event. I tried making a sub in my control that
handles MyBase.MouseUp but still this event shows up as an event the user can
use. Is there anyway to prevent users of this control from getting access to
events such as MouseUp. Thanks.
--
Dennis in Houston


Nov 21 '05 #2

P: n/a
Yes, I understand and it doesn't take any action even thought the user has
programmed some stuff for the MouseUp event. However, I wanted to actually
hide the mouseup event from the user in the design mode to where he couldn't
select the MouseUp event from the Declarations section so I wouldn't have to
explain this in the documentation.

"Richard Myers" wrote:
Gidday Dennis

I am assuming you are talking about a control that you directly inheriting from the Panel control
rather than a composite user control with a Panel on it?

In this case you need to sink the event by Overriding the OnMouseUp method of the base class in this
case the Panel. You shouldn'd Handle events raised by a base class when you are inheriting from it.
Its sloppy. By handling the event all you are doing is registering a method to observe that event
you are not taking control of it. Its kinda like subclassing a cloud. You want to subclass a cloud
so that you dont get wet if it rains. By Handling the event all you've done is pop an umbrella
above YOUR head but all the rest of us are still going to get wet becuase Handling this event for
you is not propagating the same protection to all of us.

What you need to do is turn off the rain and then no one gets wet regardless of "weather" they have
an umbrella or not. To do that you
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
' Do thing
End Sub

This event is now sunk. If on the hand you also wanted to do something with the base class you would

Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseUp(e)
MyStuffMethod()
End Sub

This would capture the base class event and perform you custom action and then spin the event out to
all who had registered for it. If you wanted to perform a custom action before turning it off then
you just wuldn;t MyBase.nMouseUp(e)
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
MyStuffMethod()
End Sub

This would perform your custom action before sinking the event. Note that implementers of your class
can still register for the event;its just that nothing will happen;if its sunk it will never be
caught by a Hnaldes clause. So you need to document this clearly.

hth
Richard
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
I have a control that inheirts from "Panel". I want to prevent the user from
having access to the MoueUp event. I tried making a sub in my control that
handles MyBase.MouseUp but still this event shows up as an event the user can
use. Is there anyway to prevent users of this control from getting access to
events such as MouseUp. Thanks.
--
Dennis in Houston


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.