2011-12-11 10 views
1

C#コードを使用してボタンをパネルの上に置く方法は?ボタンを私のパネルの上に置く方法は?

public partial class SpaceExplorer : Form 
{ 
    Button btnPlayer = new Button(); 
    Panel pGame = new Panel(); 

    public SpaceExplorer() 
    { 
     InitializeComponent(); 

     // panel: pGame 
     pGame.BackColor = System.Drawing.Color.Black; 
     pGame.Dock = System.Windows.Forms.DockStyle.Fill; 
     pGame.Location = new System.Drawing.Point(0, 24); 
     pGame.Name = "panelMain"; 

     Controls.Add(pGame); 
    } 

    private void subMenuStart_Click(object sender, EventArgs e) 
    { 
     // button: btnPlayer 
     btnPlayer.Location = new System.Drawing.Point(0, 23); 
     btnPlayer.Name = "player"; 
     btnPlayer.Size = new System.Drawing.Size(20, 20); 
     btnPlayer.BackColor = Color.White; 
     btnPlayer.Text = string.Empty; 
     btnPlayer.Enabled = false; 

     Controls.Add(btnPlayer); 
    } 
} 
+0

button1が追加されますか?もう少し詳しく、お願いします。 –

+0

@Charles:はい、パネル上のボタンが必要です。 – HelpNeeder

答えて

3
 this.button1.Location = new System.Drawing.Point(0, 0); 
     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; 
     panel1.Controls.Add(button1); 

これはパネル上に、またはパネル上のフォームに、実際にボタンをしたいですかpanel1

関連する問題