[AccessD] OT: Modify the default event handlers to mimic thebehavior of VB 6 control arrays (VB .NET)

Brett Barabash BBarabash at TappeConstruction.com
Tue Sep 14 08:46:23 CDT 2004


Looks OK to me.  Are you saying that if you had consistent behaviors for
every button on your form, that you would write separate event handlers
for each control to call another proc?  Ugh!

BTW, you can call your event procedure anything you want.  Get rid of
the Button1_ moniker and it would be much more readable:

Private Sub ButtonClickHandler(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
    Handles Button1.Click, Button2.Click

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Tuesday, September 14, 2004 3:15 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] OT: Modify the default event handlers to mimic
thebehavior of VB 6 control arrays (VB .NET)


Hi all .Net freaks

Just noticed this tip from Element K Journals.
But is it just me or would this be considered bad programming practice?
Whenever I find out an event for one control can be reused by another
control, I move that code to a subfunction.

/gustav

---

If you've been mourning the loss of control arrays in VB .NET, wipe your
eyes and listen up. While it's true that .NET put the control Index
property out to pasture, you can still point multiple controls to an
event subroutine just by modifying the event subroutines .NET exposes
automatically when you add a control to a form. For example, suppose you
have two buttons on a form named Button1 and Button2. You can make the
Click() event subroutine for Button1 also handle the Click() event for
Button2 just by adding Button2.Click to the Handles portion of the
subroutine, like so:

        Private Sub Button1_Click(ByVal sender As _ Object, ByVal e As
System.EventArgs) _
                Handles Button1.Click, Button2.Click

You can append as many control Click() events as you'd like to the
Handles statement, as long as you separate each event with a comma. As
an added bonus, you can also include other Button events or even events
from any number of non-button control types on the form. That's more
than you could ever do with a VB 6 control array.


--------------------------------------------------------------------------------------------------------------------
The information in this email may contain confidential information that 
is legally privileged. The information is only for the use of the intended 
recipient(s) named above. If you are not the intended recipient(s), you 
are hereby notified that any disclosure, copying, distribution, or the taking 
of any action in regard to the content of this email is strictly prohibited.  If 
transmission is incorrect, unclear, or incomplete, please notify the sender 
immediately. The authorized recipient(s) of this information is/are prohibited 
from disclosing this information to any other party and is/are required to 
destroy the information after its stated need has been fulfilled.

Any views expressed in this message are those of the individual
sender, except where the sender specifies and with authority,
states them to be the views of Tappe Construction Co.

This footer also confirms that this email message has been scanned
for the presence of computer viruses.Scanning of this message and
addition of this footer is performed by SurfControl E-mail Filter software
in conjunction with virus detection software.




More information about the AccessD mailing list