tags:

views:

404

answers:

1

Hi,

I have UserControl that holds Infragistics Graph control. On the TreeView sub node's right click, I have context menu as "Create Graph". This will create the new graph. This is about what i going to do.

I have confusion about what layout to use. Whether FlowLayoutPanel or TableLayoutPanel or anything else. If only one graph is add --> graph has to occupy the full form. If two graph are added --> two graph's has to split the space and so on.This is only in the format of one after another. ie First graph at top, second is below to first ..so on.

If UserControl is manually changed it should not affect the size where we displaying.

This is the WinForm. Currently i using FlowLayoutPanel, i creating panel with the constant size and added the UserControl with DockStyle.Fill. Then i added the Panel to the FlowLayoutPanel.

 GraphUserControl usr = new GraphUserControl();
 usr.Dock = DockStyle.Fill;

 Panel pnl = new Panel();

 pnl.Controls.Add(usr);

 flowLayoutpnl.Controls.Add(pnl);

What is the best approach to do this?.

+1  A: 

A TableLayoutPanel is probably your best choice, as the row heights can be set to a percentage value.

private void AddControl(Control ctl)
{
    tableLayoutPnl.RowCount += 1;
    tableLayoutPnl.RowStyles.Add(
        new RowStyle(SizeType.Percent, 100F / tableLayoutPnl.RowCount));
    ctl.Dock = DockStyle.Fill;
    tableLayoutPnl.Controls.Add(ctl, 0, tableLayoutPnl.RowCount - 1);
    foreach (RowStyle rs in tableLayoutPnl.RowStyles)
    {
        rs.Height = 100F / tableLayoutPnl.RowCount;
    }
}

You can then call this as follows:

GraphUserControl usr = new GraphUserControl();
AddControl(usr);
Patrick McDonald
Some issues with this code. Yet i using this approach. Now i using ControlCollection. At the time of adding new control, add the controls from the TableLayoutPanel are copied and TableLauoytPanel is cleared and all the controls are added newly. This lead to flickering.
Mohanavel
RE your problem with flickering, you could try calling tableLayoutPnl.SuspendLayout before and tableLayoutPnl.ResumeLayout after, this may help
Patrick McDonald