Results 1 to 7 of 7

Thread: declaring and adding a new control

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    352

    declaring and adding a new control

    How can i add a new control to a form and set its settings? Like say i want to add a command button that's 100x100 and located at (100,100), how exactly would id o this... if i can?

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    I don't think you can.The best you can do is have a command button already on the form and have it's visible property set to false.When whatever you want happens and you want to create a command button,just set the property to visible and set the top,left properties to 100.

  3. #3
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    VB Code:
    1. Option Explicit
    2. Dim WithEvents cmd As CommandButton
    3.  
    4. Private Sub AddButton()
    5.    
    6.     Set cmd = Controls.Add("VB.CommandButton", "cmdHello")
    7.     cmd.Caption = "Hello"
    8.     cmd.Width = 100
    9.     cmd.Height = 100
    10.     cmd.Visible = True
    11.     cmd.Move 100, 100
    12.  
    13. End Sub

  4. #4
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Hey pnish, that's cool!

    But how would you call other controls?
    vb.Image
    vb.Picturebox

    ...?
    I am just guessing...

    Where could we know more about that?
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    if you search in the registry for VB.CommandButton there should also be others that youu can use.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Just make the appropriate changes from command button to label
    ie :

    VB Code:
    1. Option Explicit
    2. Dim WithEvents lbl As Label
    3.  
    4. Private Sub AddButton()
    5.     Set cmd = Controls.Add("VB.Label", "lblHello")
    6.     lbl.Caption = "Hello"
    7.     lbl.Width = 100
    8.     lbl.Height = 100
    9.     lbl.Visible = True
    10.     lbl.Move 100, 100
    11. End Sub

  7. #7
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    But how would you call other controls?
    vb.Image
    vb.Picturebox
    I'm not sure but I think you can use this method with most controls. You need to Dim them using WithEvents so you can respond to their events.

    Try looking in MSDN for Controls Collection and doing a little experimenting.

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