View Single Post
  #1 (permalink)  
Old January 26th, 2005, 06:06 PM
jimmyfrank jimmyfrank is offline
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default add control at runtime, pls HELP

Re: pro vb.net 2003 "Add Dynamic Control Demo"

this sub does not work as it should: see end of line notation.
the "new" button is displayed on the screen, but thats all.


    Private Sub AddNewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewButton.Click
        Dim NewButton As Button

        'Create the new control.
        NewButton = New Button()

        'Set it up on the form.
        NewButton.Location() = New System.Drawing.Point(500, 500) ' *** Not working
        NewButton.Size() = New System.Drawing.Size(275, 123) ' *** Not working
        NewButton.Text() = "Button3" ' *** Not working

        'Addti to the forms control collection.
        Me.Controls.Add(New Button())

        'Hook up the Event Handler.
        AddHandler NewButton.Click, AddressOf Me.Button_Clicked ' *** Not working

    End Sub


Private Sub Button_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
        Dim ButtonClicked As Button
        ButtonClicked = CType(sender, Button)

        'Tell the world what button was clicked
        MessageBox.Show("You clicked " & ButtonClicked.Text)

    End Sub
Reply With Quote