473,320 Members | 1,977 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,320 software developers and data experts.

control array with code added controls

I've a bunch of labels that i haved added to a form using this code
for i = 1 to 12
for j = 1 to 12
dim lbl as new label
me.controls.add(lbl)
with lbl
...
end with
next
next

I would like to have it so that if one of these labels were click it
would change color. Any help would be appreciated. Thanks

- David

Oct 16 '06 #1
4 1085
I would like to have it so that if one of these labels were click it
would change color. Any help would be appreciated. Thanks
First create sub:

Sub SomeClick(sender as object, e as System.EventArgs)
DirectCast(sender, Label).BackColor = Color.Red
End Sub
If your for use AddHandler like this:

for i = 1 to 12
for j = 1 to 12
dim lbl as new label
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
...
end with
next
next
This should do it.
--
Pozdrav,
Josip Medved
http://www.jmedved.com

Oct 16 '06 #2
Thanks that worked great. Is there any way to figure out which label
was being click?
Josip Medved wrote:
I would like to have it so that if one of these labels were click it
would change color. Any help would be appreciated. Thanks

First create sub:

Sub SomeClick(sender as object, e as System.EventArgs)
DirectCast(sender, Label).BackColor = Color.Red
End Sub
If your for use AddHandler like this:

for i = 1 to 12
for j = 1 to 12
dim lbl as new label
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
...
end with
next
next
This should do it.
--
Pozdrav,
Josip Medved
http://www.jmedved.com
Oct 16 '06 #3
David,
As the example shows: the "sender" parameter is the label that was clicked.

You could assign the label to a locally typed variable

' VS 2005 syntax
> Sub SomeClick(sender as object, e as System.EventArgs)
Dim theLabel As Label = DirectCast(sender, Label)
If theLabel.BackColor = Color.Black Then
theLabel.BackColor = Color.Red
Else
theLabel.BackColor = Color.Black
End If
> End Sub
When you created the label you could use the Label.Tag (inherited from
Control) property to track extra information about the Label. In addition to
Label.Tag I normally use Inheritance to add additional info, via new fields
& properties to the Label control.

Public Class CustomLabel
Inherits Label

Private m_row As Integer
Private m_column As Integer

Public Property Row() As Integer
Get
Return m_row
End Get
Set(ByVal value As Integer)
m_row = value
End Set
End Property

Public Property Column() As Integer
Get
Return m_column
End Get
Set(ByVal value As Integer)
m_column = value
End Set
End Property

End Class
> for i = 1 to 12
for j = 1 to 12
dim lbl as new CustomLabel
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
.Row = i
.Column = j
> ...
end with
next
next

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"David Pick" <pi*******@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Thanks that worked great. Is there any way to figure out which label
was being click?
Josip Medved wrote:
I would like to have it so that if one of these labels were click it
would change color. Any help would be appreciated. Thanks

First create sub:

Sub SomeClick(sender as object, e as System.EventArgs)
DirectCast(sender, Label).BackColor = Color.Red
End Sub
If your for use AddHandler like this:

for i = 1 to 12
for j = 1 to 12
dim lbl as new label
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
...
end with
next
next
This should do it.
--
Pozdrav,
Josip Medved
http://www.jmedved.com
Oct 17 '06 #4
Thanks!
Jay B. Harlow wrote:
David,
As the example shows: the "sender" parameter is the label that was clicked.

You could assign the label to a locally typed variable

' VS 2005 syntax
Sub SomeClick(sender as object, e as System.EventArgs)
Dim theLabel As Label = DirectCast(sender, Label)
If theLabel.BackColor = Color.Black Then
theLabel.BackColor = Color.Red
Else
theLabel.BackColor = Color.Black
End If
End Sub

When you created the label you could use the Label.Tag (inherited from
Control) property to track extra information about the Label. In addition to
Label.Tag I normally use Inheritance to add additional info, via new fields
& properties to the Label control.

Public Class CustomLabel
Inherits Label

Private m_row As Integer
Private m_column As Integer

Public Property Row() As Integer
Get
Return m_row
End Get
Set(ByVal value As Integer)
m_row = value
End Set
End Property

Public Property Column() As Integer
Get
Return m_column
End Get
Set(ByVal value As Integer)
m_column = value
End Set
End Property

End Class
for i = 1 to 12
for j = 1 to 12
dim lbl as new CustomLabel
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
.Row = i
.Column = j
...
end with
next
next


--
Hope this helps
Jay B. Harlow
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"David Pick" <pi*******@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Thanks that worked great. Is there any way to figure out which label
was being click?
Josip Medved wrote:
I would like to have it so that if one of these labels were click it
would change color. Any help would be appreciated. Thanks

First create sub:

Sub SomeClick(sender as object, e as System.EventArgs)
DirectCast(sender, Label).BackColor = Color.Red
End Sub
If your for use AddHandler like this:

for i = 1 to 12
for j = 1 to 12
dim lbl as new label
AddHandler lbl.Click, AddressOf SomeClick
me.controls.add(lbl)
with lbl
...
end with
next
next
This should do it.
--
Pozdrav,
Josip Medved
http://www.jmedved.com
Oct 17 '06 #5

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

Similar topics

7
by: Jacky Luk | last post by:
Does anyone know of a downloadable Line ActiveX control which allows me to plot straight lines on a VC++.NET form? Thanks Jack
7
by: Tom wilson | last post by:
I'm trying to create dynamic controls in ASP.Net. It's driving me nuts. I keep getting the error: Control '16' of type 'RadioButton' must be placed inside a form tag with runat=server. Dim...
31
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
3
by: Robert Boudra | last post by:
I remember when VB.net came out that a couple of the seminars I went to mentioned that Control Arrays were going away and that there was a new and better way to execute the same code when an event...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
4
by: Rick | last post by:
Hello, I built a composite web control that has a textbox and a date control. added my custom control on a webform where there are other standard controls. Each control on the form has a...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.