2011-08-16 8 views
1

Panelコントロールに2つのボタンを含むUserControlと書いています。そして、私にはいくつかの形があります。私はこれをUserControlの形にして、底にドックさせたいと思っています。
問題は、ボタンが右揃えになっていることです。私は残したい。これを行う方法。
enter image description here PS。私はDevExpressを使用していますが、それは必要ではありません。ありがとう。パネルコントロールのボタンを合わせる

答えて

2

here'reいくつかのソリューションが最適かもしれませんが、私は

  1. 1-働くあなたは別の小さなパネルの各ボタンを作成し、 を変更することがパディングだと親パネル
  2. にこれらのけん引パネルをドッキングすることができます
  3. 2セパレータを使う方がはるかに簡単で、親パネルの色を に設定して(右にドッキングする)>右から左へ:ボタンスプリッタボタン。
+0

良い解決策。ありがとう。試してみます。 – user348173

2

winforms AFAIKのすべてのコントロールにdockというプロパティがあります。これを使って。 または、このユーザーコントロールのXとYの位置値を使用して設定できます。しかし、フォームのサイズ変更時には、コントロールの位置を変更する必要があります。

+0

私はすべてのコントロールのためにドックを使用した場合、それらは一緒に固執します。 – user348173

+0

私はあなたも特定のコントロールのためにドックを使うことができると信じています。それでなぜ1つごとに?あなたはちょうど右側の右にalighnedされている下のボタンをしたいですか? – Zenwalker

+0

はい。この場合、ボタンの間にスペースを設定することはできません。 – user348173

1

ボタンを1行2列のテーブルレイアウトアウトパネルに配置します。ここでは、行の高さ=自動サイズ、最初の列の幅は100%、2列目の幅は自動サイズです。私は各列にボタンを追加し、それぞれの上右にアンカーを設定します。

これを行うフォームのコードも提供しました。

Form.cs:System.Collections.Genericを使用して

using System; 

。 using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

名前空間WindowsFormsApplication8 { 公共部分クラスをForm1:フォーム { プライベートSystem.Windows.Forms.DataGridView dataGridView1。 private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2;

public Form1() 
    { 
     InitializeComponent(); 
    } 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    { 
     this.dataGridView1 = new System.Windows.Forms.DataGridView(); 
     this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 
     this.button1 = new System.Windows.Forms.Button(); 
     this.button2 = new System.Windows.Forms.Button(); 
     ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); 
     this.tableLayoutPanel1.SuspendLayout(); 
     this.SuspendLayout(); 
     // 
     // dataGridView1 
     // 
     this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 
     this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; 
     this.dataGridView1.Location = new System.Drawing.Point(0, 0); 
     this.dataGridView1.Name = "dataGridView1"; 
     this.dataGridView1.Size = new System.Drawing.Size(620, 269); 
     this.dataGridView1.TabIndex = 0; 
     // 
     // tableLayoutPanel1 
     // 
     this.tableLayoutPanel1.AutoSize = true; 
     this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 
     this.tableLayoutPanel1.ColumnCount = 2; 
     this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); 
     this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 
     this.tableLayoutPanel1.Controls.Add(this.button1, 1, 0); 
     this.tableLayoutPanel1.Controls.Add(this.button2, 0, 0); 
     this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; 
     this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 240); 
     this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 
     this.tableLayoutPanel1.RowCount = 1; 
     this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); 
     this.tableLayoutPanel1.Size = new System.Drawing.Size(620, 29); 
     this.tableLayoutPanel1.TabIndex = 1; 
     // 
     // button1 
     // 
     this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 
     this.button1.Location = new System.Drawing.Point(542, 3); 
     this.button1.Name = "button1"; 
     this.button1.Size = new System.Drawing.Size(75, 23); 
     this.button1.TabIndex = 0; 
     this.button1.Text = "button1"; 
     this.button1.UseVisualStyleBackColor = true; 
     // 
     // button2 
     // 
     this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 
     this.button2.Location = new System.Drawing.Point(461, 3); 
     this.button2.Name = "button2"; 
     this.button2.Size = new System.Drawing.Size(75, 23); 
     this.button2.TabIndex = 1; 
     this.button2.Text = "button2"; 
     this.button2.UseVisualStyleBackColor = true; 
     // 
     // Form1 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(620, 269); 
     this.Controls.Add(this.tableLayoutPanel1); 
     this.Controls.Add(this.dataGridView1); 
     this.Name = "Form1"; 
     this.Text = "Form1"; 
     ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); 
     this.tableLayoutPanel1.ResumeLayout(false); 
     this.ResumeLayout(false); 
     this.PerformLayout(); 

    } 
} 

}

関連する問題