using System; using System.Collections.Generic; using System.Windows.Forms; using System.Text; using System.Data; using System.Drawing; namespace DeviceApplication1 { static class Program { /// /// The main entry point for the application. /// [MTAThread] static void Main() { Application.Run( new Form1() ); } } public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Load += new EventHandler( Form1_Load ); } void Form1_Load( object sender, EventArgs e ) { int currY = 10; int heightOfControl = 30; for ( int i = 0; i < 10; i++ ) { ControlCreator cc = new ControlCreator( 10, currY, null ); foreach ( Control c in cc.ControlsToAdd ) { this.panel1.Controls.Add( c ); } currY += heightOfControl; } } /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; private System.Windows.Forms.MainMenu mainMenu1; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose( bool disposing ) { if ( disposing && ( components != null ) ) { components.Dispose(); } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.panel1 = new System.Windows.Forms.Panel(); this.SuspendLayout(); // // panel1 // this.panel1.Location = new System.Drawing.Point( 3, 3 ); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size( 234, 262 ); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF( 96F, 96F ); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoScroll = true; this.ClientSize = new System.Drawing.Size( 240, 268 ); this.Controls.Add( this.panel1 ); this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout( false ); } #endregion private System.Windows.Forms.Panel panel1; } class ControlCreator { private List controlsToAdd = new List(); public List ControlsToAdd { get { return controlsToAdd; } } public ControlCreator( int baseX, int currentY, DataRow someData ) { Label label = new Label(); label.Location = new Point( baseX, currentY ); label.Text = "Blah"; label.Size = new Size( 30, 30 ); controlsToAdd.Add( label ); TextBox text = new TextBox(); text.Location = new Point(baseX + 40, currentY); controlsToAdd.Add(text); } } }