473,883 Members | 1,681 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
13 2249
For me, the button is appearing in designer.. but not when showing the
inherited form :-(

"Johan Jooris" <jo**********@h otmail.com> wrote in message
news:Z_******** **************@ phobos.telenet-ops.be...
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 #11
Armin,

I'm a VB6 programmer just starting in VB.Net. Could you please explain what
you meant when you said that in theory, there could be several procedures in
a base class, all handling a button's Click event? I would have thought
that there could only be one event handler for a given event. How does VB
..Net decide which procedure to use when an event fires? Or does it run all
handlers associated with that event? If that's the case, how does it
determine which order to run them in?

Thanks!

Rob

"Armin Zingler" <az*******@free net.de> wrote in message
news:O0******** ******@TK2MSFTN GP11.phx.gbl...

<snip>
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

Nov 20 '05 #12
"Rob Richardson" <th*****@n2net. net> schrieb

I'm a VB6 programmer just starting in VB.Net. Could you please
explain what you meant when you said that in theory, there could be
several procedures in a base class, all handling a button's Click
event?

Private Sub Sub1( _
ByVal sender As System.Object, ByVal e As System.EventArg s) _
Handles Button1.Click

End Sub

Private Sub Sub2( _
ByVal sender As System.Object, ByVal e As System.EventArg s) _
Handles Button1.Click

End Sub

Both procedures (in the same Form) handle the Button's Click event.

I would have thought that there could only be one event
handler for a given event.
There can be none, one, several.
How does VB .Net decide which procedure
to use when an event fires? Or does it run all handlers associated
with that event?
Yes, it runs them all.
If that's the case, how does it determine which
order to run them in?


The order is undefined, or at least it shouldn't matter.
A Delegate is like a function pointer. An event is like a collection of
delegates. Raising an event means calling all delegates that have been added
to the event. In the example above, Sub1 and Sub2 have been added, so both
are called when the button raises the Click event.

See also:
http://groups.google.com/groups?selm...TNGP12.phx.gbl
--
Armin

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

Nov 20 '05 #13
Rob (& Armin),
The ease with which you can add multiple handlers for an event or multiple
events to a single handler. IMHO is one of the cooler things about .NET that
makes it so much easier then VB6!

To extend Armin's sample a little:
Private Sub Sub2( _
ByVal sender As System.Object, ByVal e As System.EventArg s) _
Handles Button1.Click, Button2.Click, Button3.Click

End Sub
Sub1 will only be executed on Button1 click, however Sub2 will be executed
for Button1, Button2 or Button3 click event. (As Armin stated, the
Button1.Click event will actually be handled by both Sub1 & Sub2).

Yes you can do it in VB6 with multiple subroutines, however you wind up with
multiple subroutines! With the new Handles syntax you can use "just the
right amount" of subroutines...

Hope this helps
Jay

"Armin Zingler" <az*******@free net.de> wrote in message
news:uU******** ******@tk2msftn gp13.phx.gbl... "Rob Richardson" <th*****@n2net. net> schrieb

I'm a VB6 programmer just starting in VB.Net. Could you please
explain what you meant when you said that in theory, there could be
several procedures in a base class, all handling a button's Click
event?

Private Sub Sub1( _
ByVal sender As System.Object, ByVal e As System.EventArg s) _
Handles Button1.Click

End Sub

Private Sub Sub2( _
ByVal sender As System.Object, ByVal e As System.EventArg s) _
Handles Button1.Click

End Sub

Both procedures (in the same Form) handle the Button's Click event.

I would have thought that there could only be one event
handler for a given event.


There can be none, one, several.
How does VB .Net decide which procedure
to use when an event fires? Or does it run all handlers associated
with that event?


Yes, it runs them all.
If that's the case, how does it determine which
order to run them in?


The order is undefined, or at least it shouldn't matter.
A Delegate is like a function pointer. An event is like a collection of
delegates. Raising an event means calling all delegates that have been

added to the event. In the example above, Sub1 and Sub2 have been added, so both
are called when the button raises the Click event.

See also:
http://groups.google.com/groups?selm...TNGP12.phx.gbl

--
Armin

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

Nov 20 '05 #14

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

Similar topics

2
2212
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
855
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
2221
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
4510
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
1112
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
3165
by: Paul Michaud | last post by:
Consider the following: Class A { .... } Class B:A { ....
2
1409
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
1954
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
11142
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...
1
10847
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
10415
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
9574
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
7971
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...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4612
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
3
3232
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.