-
Jan 9th, 2005, 08:42 AM
#1
Thread Starter
Hyperactive Member
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!
-
Jan 9th, 2005, 08:54 AM
#2
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.
-
Jan 9th, 2005, 09:06 AM
#3
Thread Starter
Hyperactive Member
Re: Create and then destroy runtime controls
I tried it as the CONTROLS.ADD but nothing happened!
Any other ideas?
-
Jan 9th, 2005, 09:10 AM
#4
Thread Starter
Hyperactive Member
Re: Create and then destroy runtime controls
To create the controls i use this code:
VB Code:
Public WithEvents Command1 As CommandButton
Private Sub Command1_Click()
MsgBox "Button Pressed"
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
.... The problem is how to remove them!
-
Jan 9th, 2005, 09:49 AM
#5
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.
-
Jan 14th, 2005, 06:33 AM
#6
Thread Starter
Hyperactive Member
Re: Create and then destroy runtime controls
Thank you szlamany! It works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|