You can "clone" an existing control that is in a control array (define one control of the type you want and set the Index to 0) on the form using Load. I define the controls I need with .Visible = false and Index = 0. Index must be asignbed at design time. I use constants to address the new controls.
Code:
'*****
'Module Declarations
Private Const idxGoback = 1
Private Const idxRefresh = 2
Private Const idxEport = 3
Private Const idxLookup = 4
Private Const idxStop = 5
Private Const idxExit = 6
'.............. later
lngLeft = 60 ' Left of first new command
With mform
.Command1(0).Visible = False
' Create 5 New command buttons based on Command1(0)
For I = 1 To 6
Load .Command1(.Command1.Ubound + 1)
With Command1((.Command1.Ubound )
.Left = lngLeft
lngLeft = .Left + .Width + 30
.Visible = True
End With
Next
.Command1(idxGoback).Caption = "Go Back"
.Command1(idxRefresh).Caption = "Refresh"
.Command1(idxEport).Caption = "EPort"
.Command1(idxLookup).Caption = "Lookup"
.Command1(idxStop).Caption = "Stop"
.Command1(idxExit).Caption = "Exit"
End With
'*** Delete Them backwards
For I = Ubound(mform.command1 to 1 Step -1 ' Not 0
On error Resume next ' Index may not Exist
Unload mform.Command1(I)
On Error GOTO 0
Next
Another option is to pass in the Control's ProgID and a control name into the Add fuction on the form's control collection's add function. That will create the control and return a reference to that new control. For example . . .
Code:
Dim ctlTextBox As VB.TextBox
Set ctlTextBox = Form1.Controls.Add("vb.TextBox", "txtSomeTextBox")
With ctlTextBox
.Top = 500
.Left = 500
.Height = 300
.Width = 2000
.Visible = True
End With
If you want to capture events off of the control, you can create a class wrapper around a reference to your control type that was dimmed WithEvents . . . that gets a bit more involved, but it is not as bad as it sounds.
- Jeff Marler B-)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.