Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

add button click event to dynamiclly created button array

HuckleHuckle Posts: 2Member
So I need to create an array of Buttons dynamiclly right,... easy

Dim WithEvents ButtonArray(1 to 32,1 to 32) as Button
--------------------------------------------------Globals ^^
For Dim i as Integer = 1 to 320 Step 10
For Dim j as Integer = 1 to 320 Step 10
ButtonArray(i/10,j/10) = new Button
with ButtonArray(i/10,j/10)
.size = (new Size(new Point(i,j))
Next
Next

GOOD! But now I need to add a click event to handle ALL of them
I figure just one click event will be OK, but the problem is I cant add a WithEvents statement to an array.
So How do I do it? will I have to write code out for ALL of them and then add a click event to handle each one? That would take sooo long. There must be a faster way, so far I have this

Sub ButtonArray_Click(Byval sender as ...., Byval e as .....) Handles ButtonArray.Click
End Sub

However like I said the WithEvents wont work with arrays. SoI dont know what todo Thanks in Advance for any Help.

~huckle

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    you Trying to do this?

    [code]
    For i = 1 to 32
    For h = 1 to 32
    AddHandler ButtonArray(i,h).Click, AddressOf ButtonSub
    Next h
    Next i
    [/code]
  • HuckleHuckle Posts: 2Member
    : you Trying to do this?
    :
    : [code]:
    : For i = 1 to 32
    : For h = 1 to 32
    : AddHandler ButtonArray(i,h).Click, AddressOf ButtonSub
    : Next h
    : Next i
    : [/code]:
    :

    Sorry Man,
    You are just a day late. I found a few workarounds for this. The solution I used did look alot like that, but a little different.

    dim op as button
    for each op in ButtonArray
    addhandler op.click, addressof ButtonArray_click
    next

    private sub ButtonArray_click(sender,e)
    end sub

    Thanks anyway for the help. The program is a cellular programmer. If you have never used one, they are a bit like logic problems and were real big in the 1980's. There are still a bunch of cool sites around for them.

    ~Huckle
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    sorry bro, I wasn't alive in the 80's :-P Well I was but I was 4yo when 1990 rolled around...

    Sorry I didn't reply sooner, I was away for the weekend, and traveling on monday.

    If you got any more questions, I try to stay active in the Vb.Net forum, i rarely visit the advance vb.net spot.
Sign In or Register to comment.