I am adding dynamic controls to a form using a class object.
in a form load section I have
Dim displayStandings As standings
Set displayStandings = New standings
Call displayStandings.setCurrentForm(frmMain)
Call displayStandings.setCurrentFrame(frameStandings)
Call displayStandings.buildStandings
The class is defined here :
Option Explicit
Dim WithEvents ctlLabel As VB.Label
Private currentForm As Form
Private currentFrame As Frame
Public Sub buildStandings()
Dim i As Integer
Dim x As Integer
x = 720
For i = 1 To 1
Set ctlLabel = currentForm.Controls.Add("VB.Label", "lblTestx" & i, currentFrame)
With ctlLabel
.AutoSize = True
.Move 2500, x, 1000, 1000
.Caption = "lblTestx222" & i
.Visible = True
.ForeColor = vbBlue
.FontUnderline = False
.MousePointer = vbDefault
End With
x = x + 240
Next i
End Sub
Public Sub setCurrentForm(ByRef newCurrentForm As Form)
Set currentForm = newCurrentForm
End Sub
Public Sub setCurrentFrame(ByRef newCurrentFrame As Frame)
Set currentFrame = newCurrentFrame
End Sub
Public Sub ctlLabel_Click()
MsgBox ("Clicked "
End Sub
I can't get the clicked to show up. If I add all this code directly in the form I have no problem. I suspect that it is because since I am creating the control dynamically with events it needs to ne in the form directly.
Has anyone tried this. Any ideas. I need to have a way to make the standings section be independant of the form since I may have to use it on another form or frame.
Any help would be great.
thanks
in a form load section I have
Dim displayStandings As standings
Set displayStandings = New standings
Call displayStandings.setCurrentForm(frmMain)
Call displayStandings.setCurrentFrame(frameStandings)
Call displayStandings.buildStandings
The class is defined here :
Option Explicit
Dim WithEvents ctlLabel As VB.Label
Private currentForm As Form
Private currentFrame As Frame
Public Sub buildStandings()
Dim i As Integer
Dim x As Integer
x = 720
For i = 1 To 1
Set ctlLabel = currentForm.Controls.Add("VB.Label", "lblTestx" & i, currentFrame)
With ctlLabel
.AutoSize = True
.Move 2500, x, 1000, 1000
.Caption = "lblTestx222" & i
.Visible = True
.ForeColor = vbBlue
.FontUnderline = False
.MousePointer = vbDefault
End With
x = x + 240
Next i
End Sub
Public Sub setCurrentForm(ByRef newCurrentForm As Form)
Set currentForm = newCurrentForm
End Sub
Public Sub setCurrentFrame(ByRef newCurrentFrame As Frame)
Set currentFrame = newCurrentFrame
End Sub
Public Sub ctlLabel_Click()
MsgBox ("Clicked "
End Sub
I can't get the clicked to show up. If I add all this code directly in the form I have no problem. I suspect that it is because since I am creating the control dynamically with events it needs to ne in the form directly.
Has anyone tried this. Any ideas. I need to have a way to make the standings section be independant of the form since I may have to use it on another form or frame.
Any help would be great.
thanks