Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Problem with anchoring to the bottom
Messages   Related Types
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
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
());
}

}

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Felix Wu(MS) (VIP)
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
());
}

}
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Lu Zhenyu
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.
Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Drawing.Color
System.Reflection.Emit.Label
System.Web.UI.MobileControls.Label
System.Web.UI.MobileControls.Panel
System.Web.UI.WebControls.Label
System.Web.UI.WebControls.Panel
System.Windows.Forms.AnchorStyles
System.Windows.Forms.Application
System.Windows.Forms.BorderStyle
System.Windows.Forms.DockStyle
System.Windows.Forms.Label
System.Windows.Forms.ListView
System.Windows.Forms.Panel
System.Windows.Forms.Splitter
System.Windows.Forms.TreeView




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734