2011-06-27 6 views
0

私は.NET UIの新機能ですが、私はtk UIプログラミングのバックグラウンドから来ており、対応する方法を見つけようとしています。おそらく、.NETには私が知らない同じ結果を達成する方法があります。.NETのwinformsカスタムコントロールパックのオプション

私がしようとしていることは、おおよそ画像1で示されています。

ヘッダーセクション、本文セクション、およびフッターセクションがあります。彼らにはそれぞれにいくつかのコントロールがあります。私が見つけようとしているのは、ヘッダーセクションとフッターセクションがそれぞれ一定の高さと水平方向に伸びるようにする方法です。身体部分をストレッチして残りを満たすようにする。ポイントの位置を計算する必要なしにこれを行う方法はありますか?ちょうど "上にパックヘッダー、下に向かってフッタをパックして、間にボディを入れてください"

答えて

1

トップコントロール - アンカー:左、右、上。
MiddleControl - アンカー:左、右、上、下。
ボトムコントロール - アンカー:左、右、下。

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; 
    } 
} 
+0

ありがとうございます。これは機能します。私のアプリケーションでは、各コントロールに合わせてカスタマイズされているので、私が離れていくことを余儀なくされていた余分な作業は、パネルの位置とサイズを手動で指定する必要があります。たとえば、呼び出し元が3つのパネルを渡すと、このクラスがそれらを配置します。しかし、私はヘッダーとフッターの高さを照会し、同じことを達成できると思います。 – dln

+0

そうです、アンカーは仕事をします。 @runtimeのサイズを変更しても、ヘッダー、フッター、本文のサイズを変更する必要があります。 –