protrader
March 12th, 2010, 10:39 AM
I've created a form which contains several controls. The main control is a tabControl, which contains several other controls. When I resize the main form, the tabs resize with no problems. But the controls in the tab are not resizing properly.
The attached screen shot, padefaultsize shows the form in it's normal state. When I resize, I expand the tab and the controls in the tab. The rest do not resize.
The screen shot paresized shows the form after I resize it. My graph (zgPeriodic) and panel (pnlPeriodic) drift outside of the tabs. I have the graph anchored at the bottom left, and the panel at the top right.
My code is as follows...
public void Form1_Resize(object sender, System.EventArgs e)
{
Control control = (Control) sender;
// resize tabPages
int tabh = (int)Math.Round((decimal)(control.Size.Height - 120));
int tabw = (int)Math.Round((decimal)(control.Size.Width - 200));
tabPages.Size = new Size(tabw, tabh);
// resize periodic tab
int periodicheight = (int)Math.Round((decimal)tabh / 2) - 2;
int zgperiodicheight = tabh - periodicheight - 45;
int gridwidth = (int)Math.Round((decimal).5775 * tabw);
int graphwidth = tabw - 12;
int pnlwidth = tabw - gridwidth - 19;
gridPeriodic.Size = new Size(gridwidth, periodicheight);
pnlPeriodic.Size = new Size(pnlwidth, periodicheight);
zgPeriodic.Size = new Size(graphwidth, zgperiodicheight);
}
The attached screen shot, padefaultsize shows the form in it's normal state. When I resize, I expand the tab and the controls in the tab. The rest do not resize.
The screen shot paresized shows the form after I resize it. My graph (zgPeriodic) and panel (pnlPeriodic) drift outside of the tabs. I have the graph anchored at the bottom left, and the panel at the top right.
My code is as follows...
public void Form1_Resize(object sender, System.EventArgs e)
{
Control control = (Control) sender;
// resize tabPages
int tabh = (int)Math.Round((decimal)(control.Size.Height - 120));
int tabw = (int)Math.Round((decimal)(control.Size.Width - 200));
tabPages.Size = new Size(tabw, tabh);
// resize periodic tab
int periodicheight = (int)Math.Round((decimal)tabh / 2) - 2;
int zgperiodicheight = tabh - periodicheight - 45;
int gridwidth = (int)Math.Round((decimal).5775 * tabw);
int graphwidth = tabw - 12;
int pnlwidth = tabw - gridwidth - 19;
gridPeriodic.Size = new Size(gridwidth, periodicheight);
pnlPeriodic.Size = new Size(pnlwidth, periodicheight);
zgPeriodic.Size = new Size(graphwidth, zgperiodicheight);
}