Building Dynamic .NET Controls with Windows Forms
page 3 of 6
by Vishal Patil
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 25606/ 16

Testing the application

Add the code given below in the form constructor.

Listing 4

public frmDynamicallyLoadingCtrls()
{
  InitializeComponent();
  string[] str = { "Field 1", "Field 2""Field 3""Maximum Length Field 4",
    "Field 5""Field 6" };
  CreateControls(str);
}

In the above listing we initialize the fields to be displayed on the form. Six fields are defined in the string array and it is passed to CreateControls method to dynamically load the controls.

Now run the form upon and the following screen will be displayed.

Figure 1

Add the field names as below in the form constructor and run the form again.

Listing 5

public frmDynamicallyLoadingCtrls()
{
  InitializeComponent();
  string[] str = { "Field 1", "Field 2""Field 3""Maximum Length Field 4",
  "Field 5""Field 6""Very Very long Maximum Length Field 7""Field 8" };
  CreateControls(str);
}

Figure 2

If you notice in both screens, Field name lengths are resized, positioned and aligned based on maximum length of label field name controls. Others controls are also aligned and positioned accordingly. Similarly, try adding or deleting field names to the string array in Listing 4.


View Entire Article

User Comments

Title: good   
Name: kumar
Date: 2010-10-14 4:28:46 AM
Comment:
Your concept is good, and give some realtime examples.
Title: ABCD   
Name: EFGH
Date: 2008-05-15 8:48:45 AM
Comment:
Good

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-18 7:01:07 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search