Results 1 to 4 of 4

Thread: Making buttons with the prog.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Tennessee
    Posts
    3

    Unhappy

    How do I make it so when you click on a button, it will add another button, plus I have a textbox so you can add whatever script you want it , so how would you make it so they click on a button, and it will make another button with whatever caption they choose and which ever script they want it such as MsgBox or somethin...i know how to do all that but dont know how to make the new button, and for it to stay when u open the prog. next time
    I posted this!

  2. #2
    Guest
    To add a button dynamically:

    Code:
    Private Sub Command1_Click()
    
    	Controls.Add "VB.CommandButton", "Button1"
    	Me!Button1.Move 0, 0
    	Me!Button1.Caption = Text1
    	Me!Button1.Visible = True
    
    End Sub
    But in this case, it's probably best to load them out of a Control Array. You make them stay on the App by saving them to the Registry when they are created, then simply loading them when the App is loaded again.

    Make a Form with a 2 CommandButton's and a TextBox. Call 1 of the CommandButton's Buttons and set it's index property to 0.

    Code:
    Private Sub Command1_Click()
        
        iCount = Buttons.Count
        Load Buttons(iCount)
        Buttons(iCount).Move 0, 0
        Buttons(iCount).Caption = Text1.Text
        Buttons(iCount).Visible = True
        
        SaveSetting "MyApp", "MySection", "ButtonCount", iCount
        SaveSetting "MyApp", "Button", iCount, Text1.Text
    
    End Sub
    
    Private Sub Form_Load()
    
        iCount = GetSetting("MyApp", "MySection", "ButtonCount")
        Print iCount
        For i = 1 To iCount
            MsgBox (i)
            Load Buttons(i)
            Buttons(i).Move 0, 0
            Buttons(i).Caption = GetSetting("MyApp", "Button", i)
            Buttons(i).Visible = True
        Next i
        
    End Sub



    [Edited by Megatron on 07-27-2000 at 08:30 PM]

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Tennessee
    Posts
    3

    Unhappy yea...but still missin one part

    That works great, but that only changes the caption...I have another text box for the buttons script part...so if someone types MsgBox "blah", it will make the button with the caption they typed, and put that command in the button, so when they open the prog again their buttin will be their so they can click it and it bring up that message box
    I posted this!

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ....

    stoluos,
    Looks like we have to wait for VB 8 or something for that. VB6 allows you to dynamically add controls, but you cannot dynamically add the events for the controls, at least to the best of my knowledge. If ever you find a solution to your problem, I am always interested to know.

    See you....



    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

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