locked
creating a new button to click RRS feed

  • Question

  • i'm having trouble executing commands for a button in a new form that i create.  I can add the button w/out any errors, but it doesn't execute the code for clicking the button.  I kinda blindly added some code that i thought i would need, but it's not working.  I want to be able to click the button and have it execute some commands:

     

    Public Class Importer

      Private form5 As Form1

      Private panel5 As Panel

      Private dot As Boolean

      Friend WithEvents done1 As System.Windows.Forms.Button

      Friend WithEvents dotnums As System.Windows.Forms.CheckBox

      Private info As New Form

     

      Public Sub New(ByRef iform As Form1, ByRef ipanel As Panel, ByRef DOTnum As Boolean)

        form5 = iform

        panel5 = ipanel

        Me.done1 = New System.Windows.Forms.Button

        Me.dotnums = New System.Windows.Forms.CheckBox

        dot = DOTnum

        With info

          .AutoSize = True

        End With

      End Sub

     

      Public Sub getinfo()

        Dim done1 As New Button

        With done1

          .Left = 200

          .Top = 180

          .Visible = True

          .Text = "Done"

        End With

        info.Controls.Add(done1)

        info.Show()

      End Sub

     

      Private Sub done1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles done1.Click

        MsgBox("hello button")

      End Sub

     

    End Class

     

     

    ps.  the icons next to the names in my toolbox are all starting to show the same general icon.  I know i read about what to do if this happens before, but i couldn't find where that information was.  If some one could help me out.  Everything still works fine, i would just like to have the default icons back.

     

    Thanks

    Friday, June 8, 2007 12:39 PM

Answers

  • After adding the button control to the controls collection of the form in GetInfo(), you could add an AddHandler statement. This will allow you to handle the done1 click event.

     

     

    Code Snippet

    info.Controls.Add(done1)

    AddHandler done1.Click, AddressOf done1_Click

     

    Friday, June 8, 2007 1:46 PM