473,702 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BUG?: VB.Net - Inherited form. Known Issue?

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.

I then built the project and added a new inherited form using this base
form. All well so far. Now, I then went to the code view of the inherited
form, chose the Overridable Button_Click event which gave me the following:

\\\
Public Overrides Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)

End Sub
///

All well and good. Code inserted in here works fine. However, for some
reason I deleted this sub from the code and went to the designer. Then I
double clicked the button to take me back to the code window and it
recreated the sub as below.

\\\
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

End Sub
///

Obviously, this isn't going to work as the base method is public
overridable... I changed the sub declaration to Public Overrides and the
error went away, but when I put code in the sub, it was executed twice when
I ran the form. Now I realised this is because both the base form and the
inherited form are handling the event, but my question is, WHY did the
double click of the control create the event in such as unusable manner? It
seems a little silly to create the event as Private, when the base method is
Public Overridable!!

Is this known about already?

Regards

Lorne
Nov 20 '05 #1
13 2231
"Lorne Smith" <no@spam.com> schrieb
Obviously, this isn't going to work as the base method is public
overridable... I changed the sub declaration to Public Overrides and
the error went away, but when I put code in the sub, it was executed
twice when I ran the form. Now I realised this is because both the
base form and the inherited form are handling the event, but my
question is, WHY did the double click of the control create the event
in such as unusable manner?

It seems a little silly to create the
event as Private, when the base method is Public Overridable!!

Is this known about already?


The designer creates the default procedure for events. Event procedures are
usually not Public Overridable. IMO, you should not change the signature in
the base class. If you want an overridable sub handling the Click, add an
Overridable OnButtonClick procedure called in the event handler of the base
class. In the derived class, override OnButtonClick.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #2

"Armin Zingler" <az*******@free net.de> wrote in message
news:uA******** ******@TK2MSFTN GP12.phx.gbl...
"Lorne Smith" <no@spam.com> schrieb
Obviously, this isn't going to work as the base method is public
overridable... I changed the sub declaration to Public Overrides and
the error went away, but when I put code in the sub, it was executed
twice when I ran the form. Now I realised this is because both the
base form and the inherited form are handling the event, but my
question is, WHY did the double click of the control create the event
in such as unusable manner?

It seems a little silly to create the
event as Private, when the base method is Public Overridable!!

Is this known about already?
The designer creates the default procedure for events. Event procedures

are usually not Public Overridable. IMO, you should not change the signature in the base class. If you want an overridable sub handling the Click, add an
Overridable OnButtonClick procedure called in the event handler of the base class. In the derived class, override OnButtonClick.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


OK, I get that, but I had been following an online seminar on MSs site, and
they showed this method of doing it (overriding the default procedure)...
It seems even more daft if the method they show in instructional videos is
not the advisable method (though I'm not too surprised by that!!)...

Lorne
Nov 20 '05 #3
"Lorne Smith" <no@spam.com> schrieb
OK, I get that, but I had been following an online seminar on MSs
site, and they showed this method of doing it (overriding the default
procedure)... It seems even more daft if the method they show in
instructional videos is not the advisable method (though I'm not too
surprised by that!!)...


It's only me saying that it is not advisable. ;-)
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

"Armin Zingler" <az*******@free net.de> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
"Lorne Smith" <no@spam.com> schrieb
OK, I get that, but I had been following an online seminar on MSs
site, and they showed this method of doing it (overriding the default
procedure)... It seems even more daft if the method they show in
instructional videos is not the advisable method (though I'm not too
surprised by that!!)...


It's only me saying that it is not advisable. ;-)
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Ah... So... Is it a bug then? Or just an idiosyncracy of how inherited
forms work? It's easy enough to work around, just that I'm in the habit of
clicking the control to generate the event, you know?

Lorne
Nov 20 '05 #5
* "Lorne Smith" <no@spam.com> scripsit:
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.

I then built the project and added a new inherited form using this base
form. All well so far. Now, I then went to the code view of the inherited
form, chose the Overridable Button_Click event which gave me the following:

\\\
Public Overrides Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)

End Sub
///
Why did you mark the handler as 'Overridable'?
All well and good. Code inserted in here works fine. However, for some
reason I deleted this sub from the code and went to the designer. Then I
double clicked the button to take me back to the code window and it
recreated the sub as below.

\\\
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

End Sub
///

Obviously, this isn't going to work as the base method is public
overridable...
Seems to be a limitation of the designer. Nevertheless, I don't
understand why you declare the handler as 'Overridable' in the base
form. Usually, you can override methods called 'On*' in the base form.
I changed the sub declaration to Public Overrides and the
error went away, but when I put code in the sub, it was executed twice when
I ran the form.


Are you sure? Maybe you want to remove the handler defined in the base
form (notice that it's an event handler)!

\\\
RemoveHandler Me.Button1.Clic k, AddressOf MyBase.Button1_ Click
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Hi,

I was also experimenting with visual inheritance of forms and I encountered
the following problem, which keeps me from using visual inheritance:
I designed a simple base form, with eg a buttoncontrol anchored at the
right - bottom corner.
I then changed the modifier of the button from friend to protected friend.

I added a new inherited forms, which inherits from this base form, adn I
change the size of the form.
When closing the form and reopening it in the designer, the button is placed
somewhere on the screen, but not on the place where it should, ie x pixels
from the right, y pixels from the button.

What am I doing wrong, or is it a bug in the vs

"Lorne Smith" <no@spam.com> schreef in bericht
news:ez******** *****@tk2msftng p13.phx.gbl...
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.

I then built the project and added a new inherited form using this base
form. All well so far. Now, I then went to the code view of the inherited form, chose the Overridable Button_Click event which gave me the following:
\\\
Public Overrides Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)

End Sub
///

All well and good. Code inserted in here works fine. However, for some
reason I deleted this sub from the code and went to the designer. Then I
double clicked the button to take me back to the code window and it
recreated the sub as below.

\\\
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

End Sub
///

Obviously, this isn't going to work as the base method is public
overridable... I changed the sub declaration to Public Overrides and the
error went away, but when I put code in the sub, it was executed twice when I ran the form. Now I realised this is because both the base form and the
inherited form are handling the event, but my question is, WHY did the
double click of the control create the event in such as unusable manner? It seems a little silly to create the event as Private, when the base method is Public Overridable!!

Is this known about already?

Regards

Lorne

Nov 20 '05 #7
"Lorne Smith" <no@spam.com> schrieb
OK, I get that, but I had been following an online seminar on
MSs site, and they showed this method of doing it (overriding the
default procedure)... It seems even more daft if the method they
show in instructional videos is not the advisable method (though
I'm not too surprised by that!!)...
It's only me saying that it is not advisable. ;-)


Ah... So... Is it a bug then?


No, by "not advisable" you (and I) referred to changing the signature in the
base class, not to the designer generated code in the derived form. So, you
can do it or you don't, but it's not a bug.
Or just an idiosyncracy of how
inherited forms work? It's easy enough to work around, just that I'm
in the habit of clicking the control to generate the event, you
know?


Maybe I got you wrong, but I can not double-click on the button in the
derived form. Well, I can, but nothing happens because it's an inherited
button.

Referring to your question:
"WHY did the
double click of the control create the event in such as unusable manner? It
seems a little silly to create the event as Private, when the base method is
Public Overridable!!"

In theory you can have several procedures in the base class, all handling
the button's click event. Some of the procedures might be private, some
public, some are overridable, some not. Do you expect the procedure,
generated in the derived form when you double-click the button (which does
not work here with me (VB 2002?)), to be overridable, public or private? It
would be ambiguous because there are procedures with different modifiers in
the base class handling the same event.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
* "Lorne Smith" <no@spam.com> scripsit:
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.

I then built the project and added a new inherited form using this base
form. All well so far. Now, I then went to the code view of the inherited form, chose the Overridable Button_Click event which gave me the following:
\\\
Public Overrides Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)

End Sub
///


Why did you mark the handler as 'Overridable'?
All well and good. Code inserted in here works fine. However, for some
reason I deleted this sub from the code and went to the designer. Then I double clicked the button to take me back to the code window and it
recreated the sub as below.

\\\
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

End Sub
///

Obviously, this isn't going to work as the base method is public
overridable...


Seems to be a limitation of the designer. Nevertheless, I don't
understand why you declare the handler as 'Overridable' in the base
form. Usually, you can override methods called 'On*' in the base form.
I changed the sub declaration to Public Overrides and the
error went away, but when I put code in the sub, it was executed twice when I ran the form.


Are you sure? Maybe you want to remove the handler defined in the base
form (notice that it's an event handler)!

\\\
RemoveHandler Me.Button1.Clic k, AddressOf MyBase.Button1_ Click
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Hi Herfried,

I was following the "Developing Windows Forms applications with Visual
Basic.NET" seminar found here:
http://msdn.ms.demoservers.com/skins/msdn-us/login.htm

In here, they did precisely what I did, changed the default event of the
button click to public overridable, then overrode it in the inherited form.
I was merely following the examples as, though I'm an experienced VB6
programmer, I've only just got around to learning .NET so was deliberately
starting at the beginning, especially as I've never used an inherited form
before (used to templates...)

I just find it rather silly that double clicking the button on the inherited
form (in VS .NET 2003 Pro), creates a default event code segment which
cannot be executed until you change it to Public Overrides and remove the
handler code at the end of the sub declaration.

Lorne
Nov 20 '05 #9
I think it is also very important to remember that when building a designer
as robust as Visual Studio, that you may not be able to please everyone.

That or its a conspiracy by microsoft to make us all better programmers...
by learning from example...

"Lorne Smith" <no@spam.com> wrote in message
news:uR******** ******@TK2MSFTN GP11.phx.gbl...

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
* "Lorne Smith" <no@spam.com> scripsit:
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.

I then built the project and added a new inherited form using this base form. All well so far. Now, I then went to the code view of the inherited form, chose the Overridable Button_Click event which gave me the following:
\\\
Public Overrides Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)

End Sub
///
Why did you mark the handler as 'Overridable'?
All well and good. Code inserted in here works fine. However, for some reason I deleted this sub from the code and went to the designer.
Then I double clicked the button to take me back to the code window and it
recreated the sub as below.

\\\
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

End Sub
///

Obviously, this isn't going to work as the base method is public
overridable...
Seems to be a limitation of the designer. Nevertheless, I don't
understand why you declare the handler as 'Overridable' in the base
form. Usually, you can override methods called 'On*' in the base form.
I changed the sub declaration to Public Overrides and the
error went away, but when I put code in the sub, it was executed twice when I ran the form.


Are you sure? Maybe you want to remove the handler defined in the base
form (notice that it's an event handler)!

\\\
RemoveHandler Me.Button1.Clic k, AddressOf MyBase.Button1_ Click
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Hi Herfried,

I was following the "Developing Windows Forms applications with Visual
Basic.NET" seminar found here:
http://msdn.ms.demoservers.com/skins/msdn-us/login.htm

In here, they did precisely what I did, changed the default event of the
button click to public overridable, then overrode it in the inherited

form. I was merely following the examples as, though I'm an experienced VB6
programmer, I've only just got around to learning .NET so was deliberately
starting at the beginning, especially as I've never used an inherited form
before (used to templates...)

I just find it rather silly that double clicking the button on the inherited form (in VS .NET 2003 Pro), creates a default event code segment which
cannot be executed until you change it to Public Overrides and remove the
handler code at the end of the sub declaration.

Lorne

Nov 20 '05 #10

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

Similar topics

2
2203
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
305
by: Nick Zdunic | last post by:
Hi, I have some forms in my application. Some visually inherited forms resize themselves in Visual Studio - ruuning my previous settings. Locking the form has no effect either. The forms it has problems with seem to be when the inheritance structure in greater than 2 levels deep. It is as follows:
0
849
by: Richard L Rosenheim | last post by:
I created and am using, an inherited control on my form. But in switching between design and code views, the IDE is screwing up the instances' declarations. Sometimes, everything is fine. But as often, the IDE adds the project name in front of the control name in the declaration and then decides the line is invalid. Occasionally, the IDE also deletes the initialization code for the control. Specifically, what's happening is that in...
2
2216
by: Joe | last post by:
OK, so i searched this forum, and it seems like my question has come close to being answered a dozen times, but never fully... I have a very simple control that inherits from UserControl. It has no child controls, just properties and custom drawing. I would like one of these properties to be 'Text'. So i setup a private _Text field (base.Text not accessible) and public String Text property. I have tried using both 'override' and 'new'...
3
4502
by: Dave Munger | last post by:
Apologies if this is a known issue, but I couldn't seem to turn it up with google or on Technet. I am using Visual C# 2005 Express, Beta 2. I am learning C# and have come to the point in the book I am reading, which covers form inheritance. Granted, the book is for Visual Studio 2003, but it directs me to use a menu item called "Add Inherited Form," available on the Project menu. This menu item, however, does not appear for me. I...
0
1105
by: Paul Lyons | last post by:
Hi, I've been having an issue using reflection and custom attributes to create objects on the fly. I was wondering if this was expected behaviour or a known bug? When using Type.GetMembers() or Type.GetMethods() on a sub class it will not return the methods marked 'internal' on the parent class. After much experimentation with BindingFlags, I discovered that in order for the methods to become visible they needed to be 'virtual' too....
3
3158
by: Paul Michaud | last post by:
Consider the following: Class A { .... } Class B:A { ....
2
1398
by: Robert Smith | last post by:
Hello, I have a problem with inherited forms in my solution. I have one project with my base forms in and another (my main project) with my inherited forms in it. There are times when I load the solution the .resx part of my inherited forms is not visible and an error occurs when you try and go into design mode with these forms. re-booting the machine, getting the latest version or re-loading the project often clears this up, however...
4
1942
by: asad.naeem | last post by:
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...
0
8739
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
9234
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
9089
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...
0
8940
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7831
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...
0
5907
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3107
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
2402
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.