.NET winforms custom controls pack options
I am new to .NET UI stuff and I came from a background with tk UI programming so I am trying to find corresponding ways of doing things. Maybe .NET has a way of achieving the same result that I don't 开发者_如何学编程know of.
So what I am trying to do is roughly illustrated in image 1.
We have a header section, a body section and a footer section. They each have a number of controls in them. What I am trying to find is a way for me to let header section and footer section each take a certain height and stretch horizontally; let body section stretch to fill the rest. Is there a way to do this without needing to calculate the point position and just say "pack header towards the top, pack footer towards the bottom and put body in between"
Top Control - Anchor: Left, Right, Top.
MiddleControl - Anchor: Left, Right, Top, Bottom.
Bottom Control - Anchor: Left, Right, Bottom.
namespace ChartApp
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.Color.Maroon;
this.panel1.Location = new System.Drawing.Point(0, 87);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(599, 266);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel2.BackColor = System.Drawing.Color.Coral;
this.panel2.Location = new System.Drawing.Point(0, 353);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(599, 86);
this.panel2.TabIndex = 1;
//
// panel3
//
this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel3.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.panel3.Location = new System.Drawing.Point(0, 0);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(600, 86);
this.panel3.TabIndex = 2;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(600, 439);
this.Controls.Add(this.panel3);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel3;
}
}
精彩评论