Label array click events ?

CdRsKuLL

Active member
Joined
Sep 26, 2006
Messages
40
Programming Experience
Beginner
I'm doing a skinable app which creates transparent labels which when clicked bitblts a button down effect on a picturebox. I have managed to create the array of labels and have them positioned right, but I cant seem to capture the click of these labels.

VB.NET:
        Do While Not lb
            labelsize = Split(ReadIni("menu", "b" & n, "0,0,0,0,0", "\skins\" + defaultskin + "\skin.ini"), ",")
            If labelsize(4) = "0" Then lb = True

            MyControlArray.AddNewLabel()
            With MyControlArray(n - 1)
                .Parent = PictureBox1
                .BackColor = Color.Transparent
                .Left = PictureBox1.Width * (labelsize(0) / picwidth)
                .Top = PictureBox1.Height * (labelsize(1) / picheight)
                .Width = PictureBox1.Width * (labelsize(2) / picwidth)
                .Height = PictureBox1.Height * (labelsize(3) / picheight)
                .Visible = True
            End With
            ReDim Preserve butcommand(n)
            butcommand(n - 1) = labelsize(4)
            n = n + 1
        Loop
above it the code which I use to create the labels, and I need help with the click event of these.

I would of though its something like ..

VB.NET:
Private Sub MyControlArray_click(ByVal Index As Integer, ByVal Sender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyControlArray.Click
        Form1.sdk(butcommand(Index))
    End Sub
but I'm getting a WithEvents variable required

the butcommand string array holds the info thats sent to the sdk sub that does the action.

can anyone shed a little light on this ?

thanks

Steve
 
arrays of event-raising objects cannot be set to raise events themselves.. you'd be better writing one event handler and assigning all the buttons to it..
 
thanks m8, just what I needed :)

ok I had a quick read on events and have it working great, I'm also usingthe label.name to hold the command I need to send.. I will also post the code I added incase it may help someone else

first I added a event handler
AddHandler MyControlArray(n - 1).Click, AddressOf MyControlArray_Click

then added the click event like this..

Private Sub MyControlArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Send command to the sdk sub
Form1.sdk(DirectCast(sender, Control).Name)
'enable fade menu out timer
Timer1.Enabled = True
End Sub

thanks again

Steve
 
Back
Top