473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Making events Private in Inheirted Controls

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
2 1290
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
3
by: Lance | last post by:
I've noticed that controls that are contained in MDI child forms fail to raise MouseLeave events if the MDI child form's MdiParent property is set to Nothing (after it was set to an existing MDI...
0
by: BigAl.NZ | last post by:
Hi Guys, I am trying to write/copy some code that uses events with a GPS. Everytime the GPS position updates the event fires. The GPS code is from a SDK Library that I got called GPS Tools...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.