By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Dynamic Form Components at Design Time

P: n/a
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?
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
MN
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?

Nov 21 '05 #2

P: n/a
Thanks for your reply. I pasted your code into my Form exactly as you have
it. Are you saying that this works for you at design time? In my
application, the code in the form's Sub New(), after InitializeComponent,
only works at runtime. I am using the first release of VB.Net.

"Charlie" wrote:
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?

Nov 21 '05 #3

P: n/a
Are you saying that you want the Form Designer to read your code to show the
form? For example, you want the designer to call a routine that looks in a
database for some parameters. No the designer will not so this.

Chris

"Charlie" <cfarrier at charlesfarriersoftware.com> wrote in message
news:FD**********************************@microsof t.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?

Nov 21 '05 #4

P: n/a
Thanks for your input.

"Chris, Master of All Things Insignifican" wrote:
Are you saying that you want the Form Designer to read your code to show the
form? For example, you want the designer to call a routine that looks in a
database for some parameters. No the designer will not so this.

Chris

"Charlie" <cfarrier at charlesfarriersoftware.com> wrote in message
news:FD**********************************@microsof t.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?


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.