Results 1 to 5 of 5

Thread: Create Control (Runtime)

  1. #1

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335

    Create Control (Runtime)

    I know it must be possible; How do i create a control (for instance a imagebox) at runtime? Lets say i want to have a person enter a number between the number 1 and 100 and when they click a button it creates that many controls. How do i accomplish this?
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. Dim i As Integer, x As Integer
    2. Dim img As Image
    3.  
    4.     i = 10
    5.  
    6.     For x = 1 To i
    7.         Set img = Controls.Add("VB.Image","Image" & x)
    8.             img.Move (x*10),0
    9.             img.Visible = True
    10.     Next

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    Originally posted by crptcblade
    VB Code:
    1. Dim i As Integer, x As Integer
    2. Dim img As Image
    3.  
    4.     i = 10
    5.  
    6.     For x = 1 To i
    7.         Set img = Controls.Add("VB.Image","Image" & x)
    8.             img.Move (x*10),0
    9.             img.Visible = True
    10.     Next

    Is this code in a Form?

  4. #4

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    this code has some bugs or something , im not saying you did it but like when i press play (i changes it to command button) when i press play i shows the buttons too close and some too far
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  5. #5

    Thread Starter
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    OK i did some work and decided to use a timer instead but your code was the core of it here is the final
    VB Code:
    1. Public i As Integer, x As Integer, y As Integer, w As Integer
    2.  
    3. Private Sub Form_Load()
    4. y = 0
    5. w = 0
    6. End Sub
    7.  
    8. Private Sub Timer1_Timer()
    9.  
    10. Dim CMD As CommandButton
    11.  
    12. i = 10
    13. y = y + 1
    14. x = y
    15. If x = 10 Then
    16. Timer1.Enabled = False
    17.     Else
    18.             Set CMD = Controls.Add("VB.CommandButton", "Command" & x)
    19.             CMD.Width = 500
    20.                    
    21.             CMD.Left = w + CMD.Width + 20
    22.             'CMD.Move (x * 100), 0
    23.             CMD.Visible = True
    24.             LImg = CMD.Left
    25.             w = CMD.Left
    26.            
    27. End If
    28. End Sub
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

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