With Deft Fingers, "Jan Driesen" <ja*********@tiscali.be> wrote:
I've an app with a bunch of Control Array of Buttons. I'll use code from my
App using 5 buttons as my example:
1) I've Dim them as a button in my Form
Dim btnUsrMonday() As Button ' User Monday Buttons
2) I've the Buttons on the Form named:
btnUsrMon1, btnUsrMon2, btnUsrMon3, btnUsrMon4, btnUsrMon5
3) I then create the Buttons Control Array in my Form
btnUsrMonday = New Button() {btnUsrMon1, btnUsrMon2, btnUsrMon3,
btnUsrMon4, btnUsrMon5}
4) Now I can control them all simply enough. Like the following will change
them all to Red with the text 'Out':
Dim i as Integer
For i = 0 To 4
btnUsrMonday(i).BackColor = Color.Red
btnUsrMonday(i).Text = "Out"
Next
What I'm looking for is a simple way to do something with ONE of them at a
time. For example, if I click on ONE of the buttons, how do I have a
sub-routine for the 'whole' array, find out which one was clicked on (ie:
btnUserMon2) and then do my colour/text change?
Obvious I can do this for each and every button. But there must be a way to
write something for the Control Array so that I can change their colour/text
when only ONE is checked (and then another, another, etc.).
I've seen a sample for Checkboxes that uses COLLECTIONS to do this... but I
can't figour out how to make it work for Buttons.
Appreciate any help.
Regards,
Bruce 3 1662
"Mr. B" <No*****@address.bot> schrieb I've an app with a bunch of Control Array of Buttons. I'll use code from my App using 5 buttons as my example:
1) I've Dim them as a button in my Form
Dim btnUsrMonday() As Button ' User Monday Buttons
2) I've the Buttons on the Form named: btnUsrMon1, btnUsrMon2, btnUsrMon3, btnUsrMon4, btnUsrMon5
3) I then create the Buttons Control Array in my Form
btnUsrMonday = New Button() {btnUsrMon1, btnUsrMon2, btnUsrMon3, btnUsrMon4, btnUsrMon5}
4) Now I can control them all simply enough. Like the following will change them all to Red with the text 'Out':
Dim i as Integer For i = 0 To 4 btnUsrMonday(i).BackColor = Color.Red btnUsrMonday(i).Text = "Out" Next
What I'm looking for is a simple way to do something with ONE of them at a time. For example, if I click on ONE of the buttons, how do I have a sub-routine for the 'whole' array, find out which one was clicked on (ie: btnUserMon2) and then do my colour/text change?
Obvious I can do this for each and every button. But there must be a way to write something for the Control Array so that I can change their colour/text when only ONE is checked (and then another, another, etc.).
I've seen a sample for Checkboxes that uses COLLECTIONS to do this... but I can't figour out how to make it work for Buttons.
You can use the same event handler for different objects:
sub ButtonClick(...) _
Handles btnUsrMon1.click, btnUserMon2.click, ...
dim btn as button = directcast(sender, button)
btn.backcolor = ...
btn.text = ...
end sub
- OR -
dim btn as button
for each btn in btnUsrMonday
addhandler btn.click, addressof ButtonClick
next btn
In this case, you don't need the Handles keyword.
--
Armin
With Deft Fingers, "Armin Zingler" <az*******@freenet.de> wrote: You can use the same event handler for different objects: dim btn as button for each btn in btnUsrMonday addhandler btn.click, addressof ButtonClick next btn
I'll look at this one as I actually have 19 buttons... so that's a bit more
than 5 (:
Thanks!
Bruce
With Deft Fingers, "Gary" <tu********@hotmail.com> wrote: You could make the click events of all the buttons share the same procedure. Then use the sender parameter Something like this: (watch for word wrap)
Okay.... I'll even try this (in reality, I've 19 buttons... not 5). So the
code might be long. But then, it's better than doing this for 19 buttons
individually.
Thanks!
Bruce This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: RBohannon |
last post by:
Is it possible to create a control array on an unbound form? I would
like to be able to loop through a series of unbound text boxes.
Thanks.
|
by: Bernie |
last post by:
Sorry, but this ia another whine about VB.Net's lack of
Control Arrays. I am new to VB.Net and I'm building an
application that uses variable number of Label controls
that are created at run...
|
by: Merlin |
last post by:
Hi
I have a control that allows embeddable editors, so for example I can set a
property of controlsEmbeddableEditor =me.TextBox1 on my form, no problem
here - what I want to do is the same thing...
|
by: B-Dog |
last post by:
I'm capturing the checked radio button to XML file using the name of the
radio button. I want to read my xml file to find which button was checked
on close and the check the appropriate button...
|
by: Robert |
last post by:
How can I declare in VB .NET an array of labels for
example and afterwards using a FOR structure load every
component of the array?
I've used this code but it doesn't work:
dim x(10) as label...
|
by: samean |
last post by:
Hello,
Could you explain me,In VB6 using control array,and how
about VB.net.
Thanks
|
by: John |
last post by:
Hello everyone,
I'm currently writing a program to keep track of schedule changes at a
school. The goal is to have someone using the program to declare changes,
then the program writes a html...
|
by: Greg |
last post by:
In VB6 I made heavy use of control arrays
I see they have been 'deprecated' in vb.Net, with a questionable explanation
that they are no longer necessary which just addresses the event issue!...
|
by: Michael D. Ober |
last post by:
In VB 6, you can create control arrays for your option groups and scan with
the following code
dim opt as OptionButton
for each opt in OptionGroup
' Do something
next opt
I know VB 2005...
|
by: Arne Beruldsen |
last post by:
I'm a recent convert to VB.net from VB6...and I can't believe they don't
support control arrays. I have an app that uses a ton of Control
Arrays...mostly labels and text boxes.
I need some...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |