This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Francis Upton |
| GOOD ANSWER |
I'm trying to have a simple form that contains two panels, the bottom panel should always be a minimum height. The top panel should grow and shrink as the form is resized vertically. There is a splitter between the two panels.
From reading the documentation and papers, here is the code I'm trying. The result of this code is the height of the top panel is initially 0; and the splitter is at the bottom edge of the form instead of between the panels as I would expect; and there is a gap between the bottom panel the the bottom of the form.
What am I doing wrong?
TIA,
Francis
--------------------------------------- using System; using System.Windows.Forms;
internal class DockTest : Form { internal DockTest() { Width = 200; Height = 200;
// Panel to fill in the space to the top, will get resized // as the bottom panel moves. Panel topPanel = new Panel(); topPanel.Dock = DockStyle.Fill; topPanel.BorderStyle = BorderStyle.Fixed3D; topPanel.Height = 100;
Label l = new Label(); l.Dock = DockStyle.Top; l.Text = "Top Panel"; l.AutoSize = true; topPanel.Controls.Add(l);
// Panel to be anchored at the bottom and docked to the bottom // Needs to be a minimum size and move when the bottom edge // is resized. Panel nextPanel = new Panel(); nextPanel.Dock = DockStyle.Bottom; nextPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left; nextPanel.BorderStyle = BorderStyle.Fixed3D; nextPanel.Height = 100;
l = new Label(); l.Dock = DockStyle.Top; l.Text = "Next Panel"; l.AutoSize = true; nextPanel.Controls.Add(l);
// Splitter between the panels Splitter topBottomSplitter = new Splitter(); topBottomSplitter.Dock = DockStyle.Bottom;
// Add in reverse order (sigh) Controls.Add(nextPanel); Controls.Add(topBottomSplitter); Controls.Add(topPanel); }
[STAThread] public static void Main(string[] args) { System.Windows.Forms.Application.Run(new DockTest ()); }
}
|
|
|
| |
|
|
| |
| |
| Felix Wu(MS) (VIP) |
| GOOD ANSWER |
I'm trying to have a simple form that contains two panels, the bottom panel should always be a minimum height. The top panel should grow and shrink as the form is resized vertically. There is a splitter between the two panels.
From reading the documentation and papers, here is the code I'm trying. The result of this code is the height of the top panel is initially 0; and the splitter is at the bottom edge of the form instead of between the panels as I would expect; and there is a gap between the bottom panel the the bottom of the form.
What am I doing wrong?
TIA,
Francis
--------------------------------------- using System; using System.Windows.Forms;
internal class DockTest : Form { internal DockTest() { Width = 200; Height = 200;
// Panel to fill in the space to the top, will get resized // as the bottom panel moves. Panel topPanel = new Panel(); topPanel.Dock = DockStyle.Fill; topPanel.BorderStyle = BorderStyle.Fixed3D; topPanel.Height = 100;
Label l = new Label(); l.Dock = DockStyle.Top; l.Text = "Top Panel"; l.AutoSize = true; topPanel.Controls.Add(l);
// Panel to be anchored at the bottom and docked to the bottom // Needs to be a minimum size and move when the bottom edge // is resized. Panel nextPanel = new Panel(); nextPanel.Dock = DockStyle.Bottom; nextPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left; nextPanel.BorderStyle = BorderStyle.Fixed3D; nextPanel.Height = 100;
l = new Label(); l.Dock = DockStyle.Top; l.Text = "Next Panel"; l.AutoSize = true; nextPanel.Controls.Add(l);
// Splitter between the panels Splitter topBottomSplitter = new Splitter(); topBottomSplitter.Dock = DockStyle.Bottom;
// Add in reverse order (sigh) Controls.Add(nextPanel); Controls.Add(topBottomSplitter); Controls.Add(topPanel); }
[STAThread] public static void Main(string[] args) { System.Windows.Forms.Application.Run(new DockTest ()); }
}
|
|
|
| |
|
|
| |
|
| |
| Lu Zhenyu |
| GOOD ANSWER |
Hello,
I also find this problem. If you change the Anchor Property, the dock property will lost its value.
Your problem has no releationship with "Anchor" at all! It do have relationship with control creating sequence. Just forget the anchor, and change the C# code order a little bit, that will be ok.
The dotnet auto-generate code could not insure the code sequence, so, you have to adjust those code secquenc or be careful of the turn to add panel controls to the form.
Here's my code:
-----------------------
using System; using System.Windows.Forms;
internal class DockTest : Form { internal DockTest() { Width = 200; Height = 200;
// Panel to be anchored at the bottom and docked to the bottom // Needs to be a minimum size and move when the bottom edge // is resized. Panel nextPanel = new Panel(); nextPanel.BorderStyle = BorderStyle.Fixed3D; nextPanel.Dock = DockStyle.Bottom; nextPanel.Height = 100;
Label l = new Label(); l.Dock = DockStyle.Top; l.Text = "Next Panel"; l.AutoSize = true; nextPanel.Controls.Add(l);
// Splitter between the panels Splitter topBottomSplitter = new Splitter(); topBottomSplitter.Dock = DockStyle.Bottom;
// Panel to fill in the space to the top, will get resized // as the bottom panel moves. Panel topPanel = new Panel(); topPanel.BorderStyle = BorderStyle.Fixed3D; topPanel.Dock = DockStyle.Fill; topPanel.Height = 100;
l = new Label(); l.Dock = DockStyle.Top; l.Text = "Top Panel"; l.AutoSize = true; topPanel.Controls.Add(l);
// Add in reverse order (sigh) Controls.Add(topPanel); Controls.Add(topBottomSplitter); Controls.Add(nextPanel); }
[STAThread] public static void Main(string[] args) { Application.Run(new DockTest()); } }
Good Luck!
-------------------------------- From: Lu Zhenyu Hebei Institute of Technology, China.
|
|
|
| |
|
|
| |
|
|
|
|
|