2011-12-11 6 views
1

C# 코드를 사용하여 패널 위쪽에 단추를 배치하는 방법은 무엇입니까?내 패널 위에 Button을 두는 방법은 무엇입니까?

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

panel1button1을 추가하거나 패널 위의 양식 것인가? 좀 더 자세하게 말해주세요. –

+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); 

이 패널에 실제로 버튼을 하시겠습니까

관련 문제