473,387 Members | 1,863 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,387 software developers and data experts.

Inherited form - Protected sub / Derived form - Private Shadows subs

Is the following behavior normal?

Both the 'Protected sub' in the inherited form and the 'Private Shadows
sub' in the derived form fires.

My interpretation of MSDN help on the topic "Shadows" does not seem to
indicate that this is the designed behavior. (the topic is rather
cryptic to me.

Here is my code;

=== In the Inherited form is this code; ===
Protected Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmForm1")
'Highlight the entire row
'Get the X and Y of the DataGrid from the mouse event
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = Me.DataGrid1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then
'Me.DataGrid1.CurrentCell = New DataGridCell(hti.Row,
hti.Column)
Me.DataGrid1.Select(hti.Row)
End If

End Sub
=== In the derived form is this code; ===

Private Shadows Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmJobCustomer")
Call PopulateStatusBarData()
Call RowSelectedToEdit()
End Sub

=========================================
Both subs fire. First the code in the inherited form and second the
code in the derived from.

This is the behavior I desire, but is this behavior what it is supposed
to do - can I rely on it?

Thank you,
Doug.

Nov 21 '05 #1
4 3730
Yes it is. You're using a handles statement which is registering each
method with the event. You'd be better off with something more like this:

' Base Class
Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MyEventHandler(e)
End Sub

Protected Overridable Sub MyEventHandler(ByVal e As
System.Windows.Forms.MouseEventArgs)
' Base Class Functionality
End Sub
' Derived Class
Protected Overrides Sub MyEventHandler(ByVal e As
System.Windows.Forms.MouseEventArgs)
MyBase.MyEventHandler(e)
' Derived Functionality
End Sub

Same result but much cleaner.

Richard

"dbuchanan" <db*********@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Is the following behavior normal?

Both the 'Protected sub' in the inherited form and the 'Private Shadows
sub' in the derived form fires.

My interpretation of MSDN help on the topic "Shadows" does not seem to
indicate that this is the designed behavior. (the topic is rather
cryptic to me.

Here is my code;od

=== In the Inherited form is this code; ===
Protected Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmForm1")
'Highlight the entire row
'Get the X and Y of the DataGrid from the mouse event
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = Me.DataGrid1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then
'Me.DataGrid1.CurrentCell = New DataGridCell(hti.Row,
hti.Column)
Me.DataGrid1.Select(hti.Row)
End If

End Sub
=== In the derived form is this code; ===

Private Shadows Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmJobCustomer")
Call PopulateStatusBarData()
Call RowSelectedToEdit()
End Sub

=========================================
Both subs fire. First the code in the inherited form and second the
code in the derived from.

This is the behavior I desire, but is this behavior what it is supposed
to do - can I rely on it?

Thank you,
Doug.

Nov 21 '05 #2
I think you can do the same thing by using the "OnMouseUp" overridable event
of the base class:

In the derived class:

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

'Do you thing here and don't call MyBase.OnMouseUp since this would in turn
call the MouseUp event in your base class. If you want to fire the MouseUp
event in the program's parent, then you can set up an event called mouseup in
the derived class and raise that event in this sub.

If you want to call that event, then add

MyBase.OnMouseUp(e)

End Sub

"Richard Myers" wrote:
Yes it is. You're using a handles statement which is registering each
method with the event. You'd be better off with something more like this:

' Base Class
Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MyEventHandler(e)
End Sub

Protected Overridable Sub MyEventHandler(ByVal e As
System.Windows.Forms.MouseEventArgs)
' Base Class Functionality
End Sub
' Derived Class
Protected Overrides Sub MyEventHandler(ByVal e As
System.Windows.Forms.MouseEventArgs)
MyBase.MyEventHandler(e)
' Derived Functionality
End Sub

Same result but much cleaner.

Richard

"dbuchanan" <db*********@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Is the following behavior normal?

Both the 'Protected sub' in the inherited form and the 'Private Shadows
sub' in the derived form fires.

My interpretation of MSDN help on the topic "Shadows" does not seem to
indicate that this is the designed behavior. (the topic is rather
cryptic to me.

Here is my code;od

=== In the Inherited form is this code; ===
Protected Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmForm1")
'Highlight the entire row
'Get the X and Y of the DataGrid from the mouse event
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = Me.DataGrid1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then
'Me.DataGrid1.CurrentCell = New DataGridCell(hti.Row,
hti.Column)
Me.DataGrid1.Select(hti.Row)
End If

End Sub
=== In the derived form is this code; ===

Private Shadows Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmJobCustomer")
Call PopulateStatusBarData()
Call RowSelectedToEdit()
End Sub

=========================================
Both subs fire. First the code in the inherited form and second the
code in the derived from.

This is the behavior I desire, but is this behavior what it is supposed
to do - can I rely on it?

Thank you,
Doug.


Nov 21 '05 #3

Hi Dennis

I disagree with what you have posted.
I think you can do the same thing by using the "OnMouseUp" overridable event of the base class:
This would require he subclass the datagrid class it wouldn;t work using
his current form class. Which means displaying message boxes from controls
which is really ugly.

In the derived class:

Protected Overrides Sub OnMouseUp(ByVal e As
System.Windows.Forms.MouseEventArgs)
.
'Do you thing here and don't call MyBase.OnMouseUp since this would in turn call the MouseUp event in your base class.
He must call MyBase.OnMouseUp ( or whatever he decides to call it) as he
has functionlity that he wishes to run in the base class. He hasn't said
he's trying to suppress the event. He simply wants to run some code in base
class to derived class order which is the whole point of using
MyBase.OnMouseUp first.

If you want to fire the MouseUp event in the program's parent, then you can set up an event called mouseup in the derived class and raise that event in this sub.

If you want to call that event, then add

MyBase.OnMouseUp(e)

End Sub
Why does he need to create another event called MouseUp? He already has
this event in both the form and the datagrid? And how does this code fire
that event?
MyBase.OnMouseUp(e) calls the sub in the base class would in turn fires the
base class MouseUp event not his custom event.

"Richard Myers" wrote:
Yes it is. You're using a handles statement which is registering each
method with the event. You'd be better off with something more like this:
' Base Class
Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MyEventHandler(e)
End Sub

Protected Overridable Sub MyEventHandler(ByVal e As
System.Windows.Forms.MouseEventArgs)
' Base Class Functionality
End Sub
' Derived Class
Protected Overrides Sub MyEventHandler(ByVal e As
System.Windows.Forms.MouseEventArgs)
MyBase.MyEventHandler(e)
' Derived Functionality
End Sub

Same result but much cleaner.

Richard

"dbuchanan" <db*********@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Is the following behavior normal?

Both the 'Protected sub' in the inherited form and the 'Private Shadows sub' in the derived form fires.

My interpretation of MSDN help on the topic "Shadows" does not seem to indicate that this is the designed behavior. (the topic is rather
cryptic to me.

Here is my code;od

=== In the Inherited form is this code; ===
Protected Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmForm1")
'Highlight the entire row
'Get the X and Y of the DataGrid from the mouse event
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = Me.DataGrid1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then
'Me.DataGrid1.CurrentCell = New DataGridCell(hti.Row,
hti.Column)
Me.DataGrid1.Select(hti.Row)
End If

End Sub
=== In the derived form is this code; ===

Private Shadows Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
MessageBox.Show("DataGrid1_MouseUp - frmJobCustomer")
Call PopulateStatusBarData()
Call RowSelectedToEdit()
End Sub

=========================================
Both subs fire. First the code in the inherited form and second the
code in the derived from.

This is the behavior I desire, but is this behavior what it is supposed to do - can I rely on it?

Thank you,
Doug.


Nov 21 '05 #4
Richard and Dennis,

Thank you for your discussion. In the mean time I made a few
discoveries and ended solving it in the following manner.

'Base Class
Protected Overridable Sub DataGrid1_MouseUp(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) Handles
DataGrid1.MouseUp
'MessageBox.Show("DataGrid1_MouseUp - frmForm1")
'Highlight the entire row
'Get the X and Y of the DataGrid from the mouse event
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = Me.DataGrid1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then
'Me.DataGrid1.CurrentCell = New DataGridCell(hti.Row,
hti.Column)
Me.DataGrid1.Select(hti.Row)
End If
'MessageBox.Show("Row highlighted")
End Sub

'Derived Class

Protected Overrides Sub DataGrid1_MouseUp(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) Handles
DataGrid1.MouseUp
'MessageBox.Show("DataGrid1_MouseUp - frmForm1")
MyBase.DataGrid1_MouseUp(sender, e)
'Local implementation
Call PopulateStatusBarData()
Call RowSelectedToEdit()
End Sub

Is this the most efficient way to do this?

-Doug

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
10
by: Chad Miller | last post by:
I currently have a base form that I inherit. The base for has a custom event. The event will not raise threw the inherited form. I was wondering if events work threw inheritance or should I use...
9
by: Brian Henry | last post by:
If i inherite a queue class into my class, and do an override of the enqueue member, how would i then go about actually doing an enqueue of an item? I am a little confused on this one... does over...
19
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works"...
4
by: JC Voon | last post by:
Hi: My base form has a button, when click it will call MessageBox.Show( "Base form" ). I inherite a child form from the base and assign a button click event to the same button which will call...
3
by: dbuchanan | last post by:
Can inherited code call derived code? If so how. I have identical 'generic' code that I am repeating again and again in several derived form because I don't know how to get inherited code to call...
5
by: MrJim | last post by:
How should variables be declared and referenced in both the base and derived form so they can be accessed?
5
by: Martin | last post by:
Hi all, I have made a usercontrol and I want to prevent the ContextMenuStrip property from being available, how can I do this? I have tried stuff like Protected Shadows ContextMenuStrip as...
4
by: EmilH | last post by:
Hi. I couldn't find it in msdn. I have a form AddCategory. Now I need EditCategory form which should look exactlay like AddCategory. I add an inherited form to the project. Now all controls'...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.