Dichiarazioni
codice:
Private m_bNumericOnly As Boolean
Private m_oForm As Form
Private m_oLbl As Label
'WithEvents allows you to capture events
'in code-generated form
Private WithEvents m_oOKBtn As CommandButton
Private WithEvents m_oCancelBtn As CommandButton
Private WithEvents m_oInput As TextBox
Routine che crea il Form
codice:
Private Sub GenerateForm()
Dim oCtl As Control
Set m_oForm = New Form1
'Clean previous instances
'of controls, if any.
'otherwise, GPF occurs
'after awhile
Set m_oOKBtn = Nothing
Set m_oCancelBtn = Nothing
Set m_oInput = Nothing
Set m_oLbl = Nothing
'clear the form
For Each oCtl In m_oForm
oCtl.Visible = False
Next
Set m_oOKBtn = m_oForm.Controls.Add("VB.CommandButton", "cmdOK")
Set m_oCancelBtn = m_oForm.Controls.Add("VB.CommandButton", "cmdCancel")
Set m_oInput = m_oForm.Controls.Add("VB.TextBox", "txtInput")
Set m_oLbl = m_oForm.Controls.Add("VB.Label", "lblInst")
With m_oForm
'Set form's width and height
.Width = 4000
.Height = 2500
.Caption = "This form was generated by VB Code only"
End With
'Setup rest of controls
With m_oLbl
.Top = 250
.Left = 250
.AutoSize = True
.FontBold = True
.Caption = IIf(m_bNumericOnly, "Enter Your Age:", "Enter Your Last Name:")
End With
With m_oInput
.Top = m_oLbl.Top + m_oLbl.Height + 250
.Left = 250
.Height = 295
If m_bNumericOnly Then
.Width = 500
.MaxLength = 3
Else
.Width = 2500
End If
End With
With m_oOKBtn
.Top = m_oInput.Top + m_oInput.Height + 375
.Width = 800
.Left = 1000
.Height = cmdGenerate(0).Height
m_oOKBtn.Caption = "&OK"
.Enabled = False
End With
With m_oCancelBtn
.Left = m_oOKBtn.Left + m_oOKBtn.Width + 100
.Top = m_oOKBtn.Top
.Width = m_oOKBtn.Width
.Height = m_oOKBtn.Height
.Caption = "&Cancel"
End With
m_oOKBtn.Visible = True
m_oCancelBtn.Visible = True
m_oLbl.Visible = True
m_oInput.Visible = True
m_oForm.Show vbModal
End Sub
Buon divertimento !!
Chiaramente il codice va pulito perchè in questa Call
ti aggiunge anche un inputbox e altro ancora ...