473,769 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1945
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********@gmai l.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********@gmai l.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.clic k event to a Protected
Overridabe subroutine with the name OnButton1Click. for example:
Private Sub btnButton1_Clic k(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.OnButton 1Click(e)
and if you dont want it to run ...don't call it.

--
Terry
"as********@gma il.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********@gmai l.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(B yVal sender As System.Object, _
ByVal e As System.EventArg s) _
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 SkipBaseButtonC lick() As Boolean
Get
Return False
End Get
End Property

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

Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles Button1.Click
If (Not SkipBaseButtonC lick) 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.Componen tModel.CancelEv entArgs)

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********@gmai l.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********@gm ail.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
2208
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 controls are visible, but you can't move them around? What exactly does it mean? There are a variety of methods for editing visuallly inherited forms and I've never had a problem with it in any version of VS.
0
2229
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 handles inheritance. Environment: OS Name Microsoft Windows 2000 Professional Version 5.0.2195 Service Pack 4 Build 2195 Microsoft Visual C# .NET
1
1575
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 displayed in the designer. Last week I used the same template and didn't have any trouble creating inherited forms. I can look at the new form in code view, and don't see any obvious errors. Help!
13
2242
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) Whilst playing with inherited forms, I created a simple base form containing a single button. I set this buttons' Click event to be public overridable and put "me.Close" in the code.
8
6715
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 contains a few controls anchored to the sides of the form. "frmChild" inherits from "frmBase"... and the controls appear on the inherited form as expected. However things start going wrong when I place addition controls on the "frmChild" form. When I...
1
2054
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 form) to the project via the IDE However, when I drop down the "(base class events)" list, I can't find the methods defined in the interface. I know the interface has been inherited because if I enter an "Implements" statement in the derived...
4
2653
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 MessageBox.Show( "Inherited form" ). I run my application, and load the clild form, click the button it show both message !!! Is there any way to control the event sequence so that it only show the child form event, or i can control whether to...
2
1755
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 this parent form. The only thing is there are no controls in the inherited form. I made all the base controls "protected". What am I dong wrong? -- ----------- Thanks,
0
1469
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 Form works perfectly but when I run the program the controls on the inherited Form are positioned based on the size of the base Form instead of the inherited Form. The controls move approriately as the Form is resized but they are never in the...
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.