Hi, I add code in Sub New, after InitializeComponent ans it works :
Public Class Form2
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
addLabel()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
Me.Text = "Form2"
End Sub
Protected Sub addLabel()
Dim lab1 As New Label
lab1.Location = New System.Drawing.Point(8, 8)
lab1.Name = "Label1"
lab1.Size = New System.Drawing.Size(284, 40)
lab1.TabIndex = 1
lab1.Text = "Hello World !"
Me.Controls.Add(lab1)
End Sub
End Class
Regards.
"Charlie" <cfarrier at charlesfarriersoftware.com> a écrit dans le message
de news:
FD**********************************@microsoft.com...
I am trying to create dynamic content in a Windows Form using external data
to determine UI elements. The code works fine at runtime. I have tried
adding code in Sub New, after InitializeComponent.
InitializeComponent apparently runs at design time as the design time view
of the Form is created, but the code after the call to InitializeComponent
appears not to run.
Is there a way to get programmer written code (not created by the code
editor) to run at design time from a Form?