473,387 Members | 3,787 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,387 software developers and data experts.

Withevents and Arrays

Is there any way I can get the effects of declaring objects using
WithEvents while also having indexed addressing?

I'm designing a control that has several buttons, the functions of which
vary only by the value of the integers they return and their visual
placement in the layout of my control. I would be saving a lot of time
and code if I could use indexed addressing [buttons(i).Text] rather than
having to address each control by a different name [button14.Text].

Any ideas on how to keep both indexed addressing *and* the withevents
declaration? Should I just declare all the buttons (button1, button2,
etc) by hand using the WithEvents keyword and then assign them to the
elements of an array?

Thanks,

-Joel
Jan 4 '06 #1
1 1477
Joel,
Are you defining a UserControl or deriving from Control itself?

You need to define an array to hold the array of buttons.

If I was defining a UserControl, I would simply place all the buttons into
an array in the constructor.

If I was deriving from Control itself, I would probably use AddHandler to
add the handler to each button's respective events.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Joel Whitehouse" <jo************@hotmail.com> wrote in message
news:OE*************@TK2MSFTNGP15.phx.gbl...
| Is there any way I can get the effects of declaring objects using
| WithEvents while also having indexed addressing?
|
| I'm designing a control that has several buttons, the functions of which
| vary only by the value of the integers they return and their visual
| placement in the layout of my control. I would be saving a lot of time
| and code if I could use indexed addressing [buttons(i).Text] rather than
| having to address each control by a different name [button14.Text].
|
| Any ideas on how to keep both indexed addressing *and* the withevents
| declaration? Should I just declare all the buttons (button1, button2,
| etc) by hand using the WithEvents keyword and then assign them to the
| elements of an array?
|
| Thanks,
|
| -Joel
Jan 4 '06 #2

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

Similar topics

7
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
1
by: Rob Smeets | last post by:
Hi you Gurus, I would like your help with my 'challenge' ;-) Any help or advice would be greatly appriciated!! I've created a Class wich retrieves FTP files. In that Class there are several...
5
by: Bradley Grant | last post by:
I am trying to write a program to access a device through USB port, there is some Visual Basic program examples that work with the device, but I am trying to write a program using C#, no luck yet,...
0
by: Steve | last post by:
Hello, I have been experimenting/learning to use aspx with and without VS2003. In VS 2003 I created a simple webform/application which contains a listbox and a label. I populate the listbox...
4
by: Shapper | last post by:
Hello, I have an aspx.vb page with this code: Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents Menu1 As MenuControl.Web.UI.Menu ... If I have my code in the aspx...
6
by: | last post by:
Is there any additional overhead for declaring a variable using the WithEvents keyword even if none of the events are being handled?
8
by: Bob Day | last post by:
Using VS 2003, VB.NET, MSDE If an event is raised in a class that was NOT instantiated with the WithEvents key word, is that event effectively ignored? Or, another way to phrase the question,...
8
by: DareDevil | last post by:
Class MyClas Friend ReadOnly WithEvents MyObject as AnotherClas .. End Clas I have a VB.NET class that has a readonly object (i.e. It can only be assigned in the constructor). This enables me...
7
by: Rob Nicholson | last post by:
A thought - has VB.NET been extended to be able to handle arrays or collections with events? A problem with VB6 was that you could only declare: Private WithEvents MyControl As MyControl ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.