News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Make a button that creates more buttons when clicked

Started by nandagopal, Nov 13, 2008, 07:02 PM

Previous topic - Next topic

nandagopal

When the form loads, it moves its button into the form's upper left corner and sizes the form to fit the button. It then positions itself randomly.


Private Sub Form_Load()
Dim x As Single
Dim y As Single

    Randomize
    cmdClickMe.Move 0, 0
    Me.Width = cmdClickMe.Width
    Me.Height = cmdClickMe.Height

    x = Int(Rnd * (Screen.Width - Me.Width))
    y = Int(Rnd * (Screen.Height - Me.Height))
    Me.Move x, y
End Sub


When you click the form's button, the event handler simply displays a new form containing a similar button.


Private Sub cmdClickMe_Click()
Dim frm As New Form1

    frm.Show
End Sub