Results 1 to 6 of 6

Thread: Create and then destroy runtime controls

  1. #1

    Thread Starter
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315

    Exclamation Create and then destroy runtime controls

    Hello,

    i am developing a program that it will create some controls (labels, textboxes, command buttons and image controls) at runtime and i will destroy them and create others!

    Can anyone help me please? I can't find a way to destroy the controls!
    I can only create them and place them in order!
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Create and then destroy runtime controls

    Have you tried .REMOVE on the CONTROLS collection?

    Not sure it works, but I would assume it does.

  3. #3

    Thread Starter
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315

    Re: Create and then destroy runtime controls

    I tried it as the CONTROLS.ADD but nothing happened!

    Any other ideas?
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  4. #4

    Thread Starter
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315

    Exclamation Re: Create and then destroy runtime controls

    To create the controls i use this code:
    VB Code:
    1. Public WithEvents Command1 As CommandButton
    2.  
    3. Private Sub Command1_Click()
    4.     MsgBox "Button Pressed"
    5. End Sub
    6.  
    7. Private Sub Form_Load()
    8.     Set Command1 = Me.Controls.Add("VB.CommandButton", "Command1", Me)
    9.     With Command1
    10.         .Visible = True
    11.         .Width = 900
    12.         .Height = 900
    13.         .Left = Me.Width / 2 - .Width / 2
    14.         .Top = Me.Height / 2 - .Height / 2
    15.         .Caption = "Test Button"
    16.     End With
    17. End Sub

    .... The problem is how to remove them!
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Create and then destroy runtime controls

    I started a project - added a command button called COMMAND2 and then posted your code and a bit more into the form. The caption for COMMAND2 is "REMOVE".

    Code:
    Public WithEvents Command1 As CommandButton
    
    Private Sub Command1_Click()
        MsgBox "Button Pressed"
    End Sub
    
    Private Sub Command2_Click()
    
    Call Me.Controls.Remove("Command1")
    
    End Sub
    
    Private Sub Form_Load()
        Set Command1 = Me.Controls.Add("VB.CommandButton", "Command1", Me)
        With Command1
            .Visible = True
            .Width = 900
            .Height = 900
            .Left = Me.Width / 2 - .Width / 2
            .Top = Me.Height / 2 - .Height / 2
            .Caption = "Test Button"
        End With
    End Sub
    This works for me.

  6. #6

    Thread Starter
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315

    Re: Create and then destroy runtime controls

    Thank you szlamany! It works
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

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