TabStrip\TableFlowLayoutPanel\Control resizing issue

S

s_armondi

Hi Group,
I'm having a problem with control resizing.
My application uses a TabStrip control (where pages are added and
removed in code, on the fly). Within the page, there are two splitters
(nested) and within one of the splitters a TableLayoutPanel, which
hosts 3 custom controls. The problems occurs when I resize the form.
The tab page which has the focus resizes as expected, but the non-
visible (non-focused) pages do not. I think I've set all of the
relevant Dock properties to the correct values - does anyone have any
suggestions?

I've pasted my code below (snipped for clarity), any suggestions are
welcome!
Thanks,
s_armondi

Screen Layout Diagram (apologies if the formatting screws it up!):
|-------------------|------------|
| | | <- Ticker 1
| dgPrices |------------|
|-------------------| | <- Ticker 2
| |------------|
| dgTicker | | <- Ticker 3
|-------------------|------------|

private void LayoutGrids()
{
TabPage pg;
BindingSource src;
DataGridView dgPrices, dgTicker;
SplitContainer primarySplitter, secondarySplitter;
//Columns
DataGridViewImageColumn showDepthCol;
DataGridViewTextBoxColumn periodCol, bidSourceCol,
bidQuantityCol, bidCol, offerCol, offerQuantityCol,
offerSourceCol, lastCol,
lastQuantityCol, lastSourceCol;


dgPrices = new DataGridView();
bindingSources.Clear();

if (clientObject.SubscribedCommodities.Length > 0)
{
foreach (string Commodity in
clientObject.SubscribedCommodities)
{
<SNIP>
//create the DataGridView for the prices.
dgPrices = new DataGridView();
//Tag is used in other code to identify the
commodity of the prices being displayed.
dgPrices.Tag = Commodity;
dgPrices.Anchor = AnchorStyles.Top |
AnchorStyles.Left;
dgPrices.AutoGenerateColumns = false;
dgPrices.RowHeadersVisible = false;
dgPrices.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;
dgPrices.AllowUserToAddRows = false;
dgPrices.AllowUserToDeleteRows = false;
dgPrices.AllowUserToOrderColumns = true;
dgPrices.AllowUserToResizeColumns = false;
dgPrices.AllowUserToResizeRows = false;
dgPrices.ClipboardCopyMode =
DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;

//event handlers
dgPrices.CellFormatting += new
DataGridViewCellFormattingEventHandler(dg_CellFormatting);
dgPrices.CellMouseClick += new
DataGridViewCellMouseEventHandler(dg_CellMouseClick);
dgPrices.MouseDown += new
MouseEventHandler(dgPrices_MouseDown);
//add the context (right-click) menu
dgPrices.ContextMenuStrip = priceContextMenu;

//store the DataGridView
priceGrids.Add(Commodity, dgPrices);

#region Column creation
<SNIP>
#endregion

dgPrices.DataSource = bindingSources[Commodity];
dgPrices.Dock = DockStyle.Fill;
bindingSources[Commodity].DataSource =
clientObject.GetData(Commodity);

//create the DataGridView for the trade ticker.
dgTicker = new DataGridView();
dgTicker.Tag = Commodity;
//dgTicker.AutoGenerateColumns = true;
dgTicker.DataSource =
tickerBindingSources[Commodity];
dgTicker.SelectionMode =
DataGridViewSelectionMode.CellSelect;
dgTicker.RowHeadersVisible = false;
tickerBindingSources[Commodity].DataSource =
clientObject.GetTickerData(Commodity);
dgTicker.Dock = DockStyle.Fill;

#region Ticker Column Creation
<SNIP>
#endregion

tickerGrids.Add(Commodity, dgTicker);

primarySplitter = new SplitContainer();
primarySplitter.Anchor = AnchorStyles.Top |
AnchorStyles.Left;
primarySplitter.Dock = DockStyle.Fill;
primarySplitter.Orientation =
Orientation.Vertical;
//split the screen 65/35
primarySplitter.SplitterDistance = (int)
(primarySplitter.Width * 0.65);
primarySplitter.SplitterMoved += new
SplitterEventHandler(primarySplitter_SplitterMoved);

secondarySplitter = new SplitContainer();
secondarySplitter.Orientation =
Orientation.Horizontal;
secondarySplitter.Dock = DockStyle.Fill;
secondarySplitter.Panel1.Controls.Add(dgPrices);
secondarySplitter.Panel2.Controls.Add(dgTicker);
secondarySplitter.SplitterMoved += new
SplitterEventHandler(secondarySplitter_SplitterMoved);


primarySplitter.Panel1.Controls.Add(secondarySplitter);

TableLayoutPanel tbl = new TableLayoutPanel();
tbl.RowCount = 3;
tbl.ColumnCount = 1;
tbl.RowStyles.Add(new RowStyle(SizeType.Percent,
100 / 3));
tbl.RowStyles.Add(new RowStyle(SizeType.Percent,
100 / 3));
tbl.RowStyles.Add(new RowStyle(SizeType.Percent,
100 / 3));
tbl.ColumnStyles.Add(new
ColumnStyle(SizeType.Percent, 100));
tbl.Dock = DockStyle.Fill;

tickerGraphs.Add(Commodity, new
TickerGraphControl[3]);
TickerGraph[] tickers =
clientObject.TickerGraphManager.GetTickerGraphs(Commodity);
TickerGraph t1 = null, t2 = null, t3 = null;
if (tickers != null)
{
if (tickers.Length > 0)
t1 = tickers[0];
if (tickers.Length > 1)
t2 = tickers[1];
if (tickers.Length > 2)
t3 = tickers[2];
}

TickerGraphControl cht = new TickerGraphControl();
cht.Dock = DockStyle.Fill;
cht.Name = "Ticker1";
cht.BackColor = this.BackColor;
cht.ContextMenuStrip = tickerContextMenu;
tbl.Controls.Add(cht, 0, 0);
cht.Ticker = t1;
tickerGraphs[Commodity][0] = cht;

cht = new TickerGraphControl();
cht.Dock = DockStyle.Fill;
cht.Name = "Ticker2";
cht.BackColor = this.BackColor;
cht.ContextMenuStrip = tickerContextMenu;
tbl.Controls.Add(cht, 0, 1);
cht.Ticker = t2;
tickerGraphs[Commodity][1] = cht;

cht = new TickerGraphControl();
cht.Dock = DockStyle.Fill;
cht.Name = "Ticker3";
cht.BackColor = this.BackColor;
cht.ContextMenuStrip = tickerContextMenu;
tbl.Controls.Add(cht, 0, 2);
cht.Ticker = t3;
tickerGraphs[Commodity][2] = cht;

primarySplitter.Panel2.Controls.Add(tbl);

pg = new TabPage(Commodity);
pg.Controls.Add(primarySplitter);
tabPrices.TabPages.Add(pg);

primarySplitters.Add(Commodity, primarySplitter);
secondarySplitters.Add(Commodity,
secondarySplitter);
}
}
else
{
<SNIP>
}
 
J

Jeff Gaines

Hi Group,
I'm having a problem with control resizing.
My application uses a TabStrip control (where pages are added and
removed in code, on the fly). Within the page, there are two splitters
(nested) and within one of the splitters a TableLayoutPanel, which
hosts 3 custom controls. The problems occurs when I resize the form.
The tab page which has the focus resizes as expected, but the non-
visible (non-focused) pages do not. I think I've set all of the
relevant Dock properties to the correct values - does anyone have any
suggestions?

This is a problem with the Tab Control, not with what you are doing.

For tab pages that are not visible the control sets their position using
large negative numbers which places them off screen. If you do your
resizing in the Tab Control Index Changed event, just for the newly
selected tab page, I think you will find it works.
 

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

Top