473,396 Members | 2,013 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,396 software developers and data experts.

Inherited form problem

hi to all
this is the problem about inheritence. I have designed a form with some
essential controls which are required for every form which will
inherited from it. for example i have Button1 on parent form and this
button is visible to me on inherited form.
The problem is:
I have written a click event of the button1 on both of the forms. tell
me the way if i click the button on inherited form only parents' click
event will be called and iherited form's evend wil not be called.

Plz guide me in this regard

Thans in advance
Asad

Jul 13 '06 #1
4 1934
I would suggest not writing a click event in the inherited form. If you
really need that there, then in the logic of that click event, you could
branch to the MyBase.Button1_Click() event instead of processing the
inherited form's code.

T

as********@gmail.com wrote:
>hi to all
this is the problem about inheritence. I have designed a form with some
essential controls which are required for every form which will
inherited from it. for example i have Button1 on parent form and this
button is visible to me on inherited form.
The problem is:
I have written a click event of the button1 on both of the forms. tell
me the way if i click the button on inherited form only parents' click
event will be called and iherited form's evend wil not be called.

Plz guide me in this regard

Thans in advance
Asad
Jul 13 '06 #2
but i have some code related to inherited form but in some cases i
want to stop that code to execute.
tomb wrote:
I would suggest not writing a click event in the inherited form. If you
really need that there, then in the logic of that click event, you could
branch to the MyBase.Button1_Click() event instead of processing the
inherited form's code.

T

as********@gmail.com wrote:
hi to all
this is the problem about inheritence. I have designed a form with some
essential controls which are required for every form which will
inherited from it. for example i have Button1 on parent form and this
button is visible to me on inherited form.
The problem is:
I have written a click event of the button1 on both of the forms. tell
me the way if i click the button on inherited form only parents' click
event will be called and iherited form's evend wil not be called.

Plz guide me in this regard

Thans in advance
Asad

Jul 13 '06 #3
Hi,
This is from F. Balena's book "Visual Basic 2005: The Language". In the
base form, delegate the base forms btnBotton1.click event to a Protected
Overridabe subroutine with the name OnButton1Click. for example:
Private Sub btnButton1_Click(byval Sender as Object, ....etc
OnButton1Click(e)
end sub

Protected Overridable Sub OnButton1Click(e as EventArgs)
"your code for the base form here"
end sub
then in the derived form:
Protected Overrides Sub OnButton1Click(e as EventArgs)
Then if you want the base form OnButton1Click to run .. call it ...
MyBase.OnButton1Click(e)
and if you dont want it to run ...don't call it.

--
Terry
"as********@gmail.com" wrote:
but i have some code related to inherited form but in some cases i
want to stop that code to execute.
tomb wrote:
I would suggest not writing a click event in the inherited form. If you
really need that there, then in the logic of that click event, you could
branch to the MyBase.Button1_Click() event instead of processing the
inherited form's code.

T

as********@gmail.com wrote:
>hi to all
>this is the problem about inheritence. I have designed a form with some
>essential controls which are required for every form which will
>inherited from it. for example i have Button1 on parent form and this
>button is visible to me on inherited form.
>The problem is:
>I have written a click event of the button1 on both of the forms. tell
>me the way if i click the button on inherited form only parents' click
>event will be called and iherited form's evend wil not be called.
>
>Plz guide me in this regard
>
>Thans in advance
>Asad
>
>
>

Jul 13 '06 #4
Hello, Asad,

I'm not sure that I understand the problem.

Why can't you just put the code of the inherited form's event handler
into a conditional block? I.e. something like:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
If (Appropriate...) Then
Do actions...
End If
End Sub

Is it actually the code of the event handler in the Base form that you
need to inhibit? In this case, I would either:

a) Define an overridable property to control when the Base form code is
executed. E.g. something like:

Protected Overridable ReadOnly _
Property SkipBaseButtonClick() As Boolean
Get
Return False
End Get
End Property

Then test this property in the Base form's handler:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
If (Not SkipBaseButtonClick) Then
Do actions...
End If
End Sub

Override the property in the inherited form and return either True or
False as appropriate.
or
b) Define a new event in the Base form that includes a "Cancel"
argument. E.g. something like:

Public Event BaseButtonClick(_
ByVal sender As System.Object, _
ByVal eCancel As System.ComponentModel.CancelEventArgs)

Raise this new event in the Base form handler and only execute the base
form code if the "cancel" property of eCancel is not returned as True.
Then in the inherited form Handle BaseButtonClick instead of Button1.Click.

But let me know if it is something else that you are looking for.

Cheers,
Randy
as********@gmail.com wrote:
but i have some code related to inherited form but in some cases i
want to stop that code to execute.
tomb wrote:
>>I would suggest not writing a click event in the inherited form. If you
really need that there, then in the logic of that click event, you could
branch to the MyBase.Button1_Click() event instead of processing the
inherited form's code.

T

as********@gmail.com wrote:

>>>hi to all
this is the problem about inheritence. I have designed a form with some
essential controls which are required for every form which will
inherited from it. for example i have Button1 on parent form and this
button is visible to me on inherited form.
The problem is:
I have written a click event of the button1 on both of the forms. tell
me the way if i click the button on inherited form only parents' click
event will be called and iherited form's evend wil not be called.

Plz guide me in this regard

Thans in advance
Asad

Jul 14 '06 #5

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

Similar topics

2
by: Jeff Levinson [mcsd] | last post by:
I guess I would have to know what you mean by "not being able to edit the forms". Does this mean you get an error in the designer when you try to display an inherited form? Does this mean the...
0
by: Frnak McKenney | last post by:
I'm running into problems with VisualStudio.NET2003 and Windows Forms inheritance. It _feels_ like a bug, but it could just as well be a misunderstanding on my part regarding how the VS Designer...
1
by: RRiness | last post by:
I'm trying to use a template form I created. When I add an inherited form to my project, I get the error: Object reference not set to an instance of an object. when the inherited form is...
13
by: Lorne Smith | last post by:
Hi, First, sorry for the crosspost, but it seemed appropriate... :) I've come accross what I consider to be a bug, but I don't know if it's already known or not. (VS .Net 2003 Pro - VB.Net) ...
8
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
1
by: skootr | last post by:
I have a Public Interface defined in a class module. I also have a form that implements that interface After building the solution, I added an Inherited Form (inherited from the above-mentioned...
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...
2
by: Steve Teeples | last post by:
I have a simple form with a panel that is docked in the base form. The panel has three controls - two buttons and one treeview. I use "Inherited Form" when creating a second form derived from...
0
by: Paul W | last post by:
Hello everyone, My problem is with an inherited Form. The base Form has a few controls on it that are anchored such that they move as the Form is resized. While in the designer, the inherited...
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: 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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.