473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Dynamic Form Components at Design Time

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
4 2118
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jonathan | last post by:
hey all, I'd like to implement an application that is truly dynamic: the components are not only just known at runtime, but also the components are unknown at runtime: ie: some don't even ship...
13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
4
by: Adam Clauss | last post by:
This may be more of a Visual Studio question than a C# question, but it came up within the context of a C# app, so here it is. In a Windows Form or a Web Form application, you can drag various...
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
2
by: Undecided | last post by:
I need to do this. I have a business control that's when dropped on a form has to create all the gui components that it needs. These will be created at design time and their properties will be...
14
by: Jan Nielsen | last post by:
Hi In Microsoft Access it is possible to write code like this Sub test() DoCmd.OpenForm "TestForm", acDesign Dim a As Control For Each a In Forms("TestForm").Controls Do stuff Next End Sub
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
21
by: Simon Verona | last post by:
Hope somebody can help! I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I've written to a form. Specifically, I'm trying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.