G
Gary Kahrau
I am trying to add some components dynamically.
It works if the code is within form1.
When I try to move it to a module, I don't get any errors, but the
components don't display.
also the addhandler syntac is giving me trouble.
AddHandler cb2.Click, AddressOf fx.cbDesignTime_Click(fx, ee)
Below is the sample module code.
Thanks,
Gary...
Public Module module1
' Inherits System.Windows.Forms.Form
Public Sub Create_Objects()
Dim x As Integer
Dim cbCount As Integer
Dim fx As New Form1
fx.Panel1.Visible = True
fx.Refresh()
Dim ee As New System.EventArgs
'create controls for the amount in the textbox
Try
For x = 0 To 4
' For x = 0 To CType(tbButtonAmount.Text, Integer) - 1
Dim cb2 As New System.Windows.Forms.Button
cb2.Size = New System.Drawing.Size(120, 30)
cb2.Location = New System.Drawing.Point(250, 40 + x * 40)
cb2.Name = "RunTime" & CStr(cbCount)
cb2.Text = "RunTime" & CStr(cbCount)
fx.Controls.Add(cb2)
cbCount += 1
'add the click event and point to existing click event
' AddHandler cb2.Click, AddressOf fx.cbDesignTime_Click(fx, ee)
Next
Catch
MsgBox("Please ensure you have entered a number of controls to create in the
texbox!")
fx.tbButtonAmount.Select()
End Try
End Sub
End Module
It works if the code is within form1.
When I try to move it to a module, I don't get any errors, but the
components don't display.
also the addhandler syntac is giving me trouble.
AddHandler cb2.Click, AddressOf fx.cbDesignTime_Click(fx, ee)
Below is the sample module code.
Thanks,
Gary...
Public Module module1
' Inherits System.Windows.Forms.Form
Public Sub Create_Objects()
Dim x As Integer
Dim cbCount As Integer
Dim fx As New Form1
fx.Panel1.Visible = True
fx.Refresh()
Dim ee As New System.EventArgs
'create controls for the amount in the textbox
Try
For x = 0 To 4
' For x = 0 To CType(tbButtonAmount.Text, Integer) - 1
Dim cb2 As New System.Windows.Forms.Button
cb2.Size = New System.Drawing.Size(120, 30)
cb2.Location = New System.Drawing.Point(250, 40 + x * 40)
cb2.Name = "RunTime" & CStr(cbCount)
cb2.Text = "RunTime" & CStr(cbCount)
fx.Controls.Add(cb2)
cbCount += 1
'add the click event and point to existing click event
' AddHandler cb2.Click, AddressOf fx.cbDesignTime_Click(fx, ee)
Next
Catch
MsgBox("Please ensure you have entered a number of controls to create in the
texbox!")
fx.tbButtonAmount.Select()
End Try
End Sub
End Module