Results 1 to 11 of 11

Thread: How do I create command buttons on the fly?

  1. #1
    Guest
    If you want to add a CommandButton, at runtime, use this code.

    Code:
    Private Sub Command1_Click()
    
         Controls.Add "VB.CommandButton", "Command1"
         Me!Command1.Move 0, 0
         Me!Command1.Caption = "My Button"
         Me!Command1.Visible = True
    
    End Sub

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    clever, meg - much better than mine!

    pause while I file it away for future reference...

  3. #3
    Guest
    Keep in mind, this only works in VB6. If you do not have VB6, you can always load them from a Control Array, so you need at least 1 instance of it on the Form and make sure that the Index is set to 0.

    Code:
    Private Sub cmdButton_Click()
    
       Load Comand1(1)
       Command1(1).Move 0, 0
       Command1(1).Caption = "My Button"
       Command1(1).Visible = True
    
    End Sub

  4. #4
    New Member
    Join Date
    Jun 2000
    Posts
    15

    Thanxs All

    thanxs all for the replay, now i can go 2 sleep......at last

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    why - what's your time there?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Guest
    It's pretty confusing when you have so many people in so many different time zones.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    yeah, it gets tricky after a while, but if you get your TZ settings on your profile right, it's not so bad. however, when my outlook inbox says that I received the notification at 3 in the morning I get confused then when the thread says it was a different time!
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Thumbs up

    Thats right guys, the same thing in here too

  9. #9
    Lively Member
    Join Date
    Jun 2000
    Posts
    67
    Hmmm. pretty good you guys but I dont know what kind of program you want but if you want a button to appear when some one else clicks another button (or does anything else) then

    Private Sub Form_load()
    Command1.visible=false
    end sub

    Private Sub Command2_click()
    Command2.visible = true
    end sub


    THATS THE CHEAP WAY TO DO IT BUT IT TAKES LESS CODE!

    IF YOU CAN'T DO IT, FIND A WAY AROUND IT!

  10. #10
    Guest
    But that way, you have already created it. In my method above, you create it from scratch.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    er...nitrolic2...if you make command2 visible when you click on it you can't click on it - invisible objects don't receive events.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width