toby_nance
March 29th, 2003, 03:04 PM
I am trying to create a new ControlCollection that will have all of the child controls drawn on my form.
How do I get my form to draw all the child controls to my own ControlCollection?
I've included a simple example of what I'm trying to do. Uncomment the last two lines in the constructor to see how it acts with the built in ControlCollection.
toby_nance
March 29th, 2003, 03:07 PM
My attachment didn't seem to work, so here's the code:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
public class PanelTest : Form
{
public Panel pnl1;
public Panel pnl2;
public Label lbl1;
public Label lbl2;
public Label lbl3;
public System.Windows.Forms.Control.ControlCollection ctrls;
//*************************************************************
//*** TreeTest ***
//*************************************************************
public PanelTest()
{
ctrls = new System.Windows.Forms.Control.ControlCollection(this);
Size = new System.Drawing.Size(600, 600);
Location = new System.Drawing.Point(0, 0);
lbl1 = new Label();
lbl1.Text = "lbl1";
lbl1.Location = new System.Drawing.Point(10, 10);
lbl2 = new Label();
lbl2.Text = "lbl2";
lbl2.Location = new System.Drawing.Point(10, 10);
lbl3 = new Label();
lbl3.Text = "lbl3";
lbl3.Location = new System.Drawing.Point(10, 10);
pnl1 = new Panel();
pnl2 = new Panel();
pnl1.Size = new System.Drawing.Size(400, 400);
pnl2.Size = new System.Drawing.Size(200, 200);
pnl1.BorderStyle = BorderStyle.Fixed3D;
pnl2.BorderStyle = BorderStyle.Fixed3D;
pnl1.Location = new System.Drawing.Point(10, 50);
pnl2.Location = new System.Drawing.Point(10, 50);
pnl1.Controls.Add(lbl2);
pnl1.Controls.Add(pnl2);
pnl2.Controls.Add(lbl3);
ctrls.Add(lbl1);
ctrls.Add(pnl1);
//Controls.Add(lbl1);
//Controls.Add(pnl1);
}
//*************************************************************
//*** Main ***
//*************************************************************
static void Main()
{
Application.Run(new PanelTest());
}
}