how to handle events for runtime created controls in vb.net

hi
i am creating a button control at runtime in my vb.net application,
i want to open a particular form for every button click event which i created in runtime
my problem is how to handle events for that controls
help needed to solve this

LuV
PurpleHaze

Comments

  • I hope i have understood your question correctly..
    Even if you create a button at run-time you would have declared it correct?..So assuming you create 2 buttons at run-time in the manner shown here

    dim b1 as Button = new Button("Button1")
    dim b2 as Button = new Button("Button2")

    me.controls.add(b1)
    me.controls.add(b2)

    The event handler would be:-

    Private Sub X (byval sender as Object,byval e as Eventargs) handles b1.click
    'open form as required
    end Sub

    Similarly for button b2..
    Private Sub Y (byval sender as Object,byval e as Eventargs) handles b2.click
    'open form as required
    end Sub

    If the event handlers are to be the same for both b1 and b2 then you can use..
    Private Sub X (byval sender as Object,byval e as Eventargs) handles b1.click,b2.click
    'open form as required
    end Sub
Sign In or Register to comment.

Howdy, Stranger!

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

Categories

In this Discussion