2013-04-29 7 views
0

아주 사소한 일이지만 내 문제는 그 중 하나가 클릭 될 때 두 개의 버튼을 삭제해야한다는 것입니다. 이 코드는 3 초가 지나면 두 버튼을 생성합니다. 내가 원한 것은 이러한 옵션들 중 하나가 무언가를 (이 작업은) 완료하고 일단 완료되면이 버튼을 다시 사라지게 만드는 것입니다. 당신은 버튼을 비활성화 할 수 있습니다다른 버튼을 클릭하면 버튼을 삭제하는 방법은 무엇입니까?

private void d_Click(object sender, EventArgs e) 
{ 
    this.Controls.Remove(btnDice); // This doesnt work 
} 
+1

버튼을 숨길 수 있습니다. btnDice.Visible = false; – Max

+0

당신이 처음이었습니다. 그러나 실제로는 보이지 않는 것을 – DiederikEEn

+0

으로 만들고 다시 보게하십시오 : btnDice.Visible = true? – Sizza

답변

1

이 버튼을 제거하는데 내 실패한 시도가

this.btnDice.Enabled = false; 

또는 사용할 수를 사용하고 아래

private void btnRandom_Click(object sender, EventArgs e) 
{ 
    Button d = new Button(); 
    Button c = new Button(); 
    d.Text = "Dice"; 
    c.Text = "Chance Card"; 
    d.Name = "btnDice"; 
    c.Name = "btnCC"; 
    d.Location = new Point(btnRandom.Location.X, btnRandom.Location.Y + 30); 
    c.Location = new Point(btnRandom.Location.X, btnRandom.Location.Y + 60); 
    d.Click += new EventHandler(d_Click); 
    c.Click += new EventHandler(c_Click);    
    this.Controls.Add(d); 
    this.Controls.Add(c); 
} 

그리고 다음은 두 개의 버튼을 생성하는 코드는 그것을 숨길 수있는 visible 속성 예

this.btnDice.Visible = false; 

제거하기 양식을 새로 고침해야 할 수 있습니다.

0

당신은 sender를 제거하여이 시도 할 수 있습니다 :

private void d_Click(object sender, EventArgs e) 
{ 
    this.Controls.Remove((Button)(sender)); 
    this.Refresh(); 
} 
0

왜 그냥 버튼이 사라지고 다시 다시 만들지 마라?

//Make the button disappear 
this.btnDice.Visible = false; 

//Make the button reappear 
this.btnDice.Visible = true; 
관련 문제