A WinForms application. One of the forms consists of a MenuStrip
, a custom control LabelProgressBar
below that, and a TableLayoutPanel
below that.
While the program is running, the size of the LabelProgressBar
is changed. The TableLayoutPanel
should expand or contract as it is resized. So, if the height of the LabelProgressBar
is reduced to zero, it should look as if the TableLayoutPanel
and its contents are directly below the MenuStrip
.
A screenshot can be included if it would be helpful.
So, far attempts have been made with various dock and anchor arrangements for the appropriate controls, and none resulted in the required behaviour.
This works perfectly with two panels - one for the top, with DockStyle.Top
, and the "main" one with DockStyle.Fill
.
You could try wrapping your custom control in a panel and experiment with anchoring or Fill
'ing, if it doesn't dock properly to the top.
var form = new Form();
var shrinking = new Panel()
{
BackColor = Color.Red,
Dock = DockStyle.Top
};
var filling = new TableLayoutPanel()
{
BackColor = Color.Green,
Dock = DockStyle.Fill
};
var timer = new System.Windows.Forms.Timer();
timer.Interval = 500;
timer.Tick += (s, a) =>
{
shrinking.Height -= 10;
if(shrinking.Height <= 0) {
shrinking.Height = 0;
timer.Stop();
}
};
form.Shown += (s, a) => timer.Start();
// Just to make sure it works with a menu present
var menu = new MenuStrip();
menu.Items.Add("&File");
form.Controls.Add(shrinking);
form.Controls.Add(filling);
form.Controls.Add(menu);
form.ShowDialog();