|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
control array with code added controlsI'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 > I would like to have it so that if one of these labels were click it First create sub:> would change color. Any help would be appreciated. Thanks 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. Thanks that worked great. Is there any way to figure out which label
was being click? Josip Medved wrote: Show quoteHide quote > > 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 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 .Row = i>> for j = 1 to 12 >> dim lbl as new CustomLabel >> AddHandler lbl.Click, AddressOf SomeClick >> me.controls.add(lbl) >> with lbl .Column = j >> ... >> end with >> next >> next -- Show quoteHide quoteHope this helps Jay B. Harlow ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "David Pick" <pickda***@gmail.com> wrote in message news:1161030764.768724.91680@i3g2000cwc.googlegroups.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 > Thanks!
Jay B. Harlow wrote: Show quoteHide quote > 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" <pickda***@gmail.com> wrote in message > news:1161030764.768724.91680@i3g2000cwc.googlegroups.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 > >
load form in vb.net
How to raise a shortcut picking off each digit of an integer How to use binary files as resources in VB 2005 Need help updating my dataset with changes made on the Source? Getchanges Merge? Problem bei der Installation eines VB.net Programms Re: What .NET classes are SLOW vs. API? vb.net database programming Getting external IP Address Is there a equivalent to 'Last Position' in VS2005? |
|||||||||||||||||||||||