|
RE: Indexing controls on windows forms
|
vic_ng-@xs4all.nl
|
Apr 17, 2010 03:02 PDT
|
Reinhard Neuwirth wrote:
| |
VB6.0 provided for controls to be grouped in group boxes and to be
indexed, so that clicking any one of the controls invoked a single click
handler in which actions could be defined by selecting on the index.
This feature seems to have disappeard from VB2010. Looping through every
control in a group box's control collection is possible, but I have been
unable to assign a single click handler for the whole collection. I'd be
grateful for ideas.
Jessica
|
Hi Jessica,
The group box still provides one-only selection functionality for
RadioButtons, but apart from that there is a general way for coding
events for multiple controls in VB.Net.
Shift-select the controls in the Designer and then click the
lighting-bolt button at the top of the Properties window. You'll get a
list of all the events. Double-click an event, and the boilerplate code
for that event appears in the code window. It has multiple handles
clauses, so the code will work for all the selected controls. For
example:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) _
Handles RadioButton3.CheckedChanged, RadioButton2.CheckedChanged,
RadioButton1.CheckedChanged
End Sub
You can also select individual controls by casting the sender argument
to the control type. Alternatively you can change "sender As
System.Object" to "sender As RadioButton" or whatever they are.
hope this helps, Vic
|
|
 |
|