Withevents and Arrays

  • Thread starter Joel Whitehouse
  • Start date
J

Joel Whitehouse

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
 
J

Jay B. Harlow [MVP - Outlook]

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


| 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top