CompositeControlDesigner -

A

Alessandro Zifiglio

hi sebastian, that sample code is a good example showing how to create
editabledesignerregions, however some pieces of code are missing.
Specifically they forgot(or maybe its intentional) to include the lines of
code that add the controls in the templates(view1 and view2) into the
specified content region. The missing code in the CreateChildControls method
is :
if (CurrentView == 0)
{
if (View1 != null)
{
View1.InstantiateIn(tc);
}
}
else if (CurrentView == 1)
{
if (View2 != null)
{
View2.InstantiateIn(tc);
}
}


The complete code for the CreateChildControls method after the above
modification is :
// Create a simple table with a row of two clickable,
// readonly headers and a row with a single column, which
// is the 'container' to which we'll be adding controls.
protected override void CreateChildControls()
{
// Always start with a clean form
Controls.Clear();

// Create a table using the control's declarative properties
Table t = new Table();
t.CellSpacing = 1;
t.BorderStyle = BorderStyle;
t.Width = this.Width;
t.Height = this.Height;

// Create the header row
TableRow tr = new TableRow();
tr.HorizontalAlign = HorizontalAlign.Center;
tr.BackColor = Color.LightBlue;

// Create the first cell in the header row
TableCell tc = new TableCell();
tc.Text = "View1";
tc.Width = new Unit("50%");
tr.Cells.Add(tc);

// Create the second cell in the header row
tc = new TableCell();
tc.Text = "View 2";
tc.Width = new Unit("50%");
tr.Cells.Add(tc);

t.Rows.Add(tr);

// Create the second row for content
tr = new TableRow();
tr.HorizontalAlign = HorizontalAlign.Center;

// This cell represents our content 'container'
tc = new TableCell();
tc.ColumnSpan = 2;
if (CurrentView == 0)
{
if (View1 != null)
{
View1.InstantiateIn(tc);
}
}
else if (CurrentView == 1)
{
if (View2 != null)
{
View2.InstantiateIn(tc);
}
}
tr.Cells.Add(tc);

t.Rows.Add(tr);

// Add the finished table to the Controls collection
Controls.Add(t);
}

Have a good easter,
Alessandro Zifiglio.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top