2012-12-18 37 views
0

我已經寫的,所以我的代碼:我應該把這些看得見的變化對他們顯示

private void radioSelectButton_Click(object sender, EventArgs e) 
{ 
    if (pteriRadio.Checked) // Selecting avatar to be displayed from here on out. 
    //This avatar will also be displayed on the game board. 
    { 
     pteriBox1.Visible = true; 
     xweetokBox1.Visible = false; 
     ixiBox1.Visible = false; 
     label1.Text = ("Pteri Inventory"); 
     player1avatar = "pteri"; 
    } 
    else if (xweetokRadio.Checked) 
    { 
     xweetokBox1.Visible = true; 
     pteriBox1.Visible = false; 
     ixiBox1.Visible = false; 
     label1.Text = ("Xweetok Inventory"); 
     player1avatar = "xweetok"; 
    } 
    else if (ixiRadio.Checked) 
    { 
     ixiBox1.Visible = true; 
     pteriBox1.Visible = false; 
     xweetokBox1.Visible = false; 
     label1.Text = ("Ixi Inventory"); 
     player1avatar = "ixi"; 
    } 
    characterSelectBox.Visible = false; 
    radioSelectButton.Visible = false; 
    characterSelectBox2.Visible = true; 
    radioSelectButton2.Visible = true; 
} 

它好像能見度的變化時,我有像這樣應該顯示,與內部的變化按鈕點擊但在if語句之外(用戶選擇的內容無關緊要,一旦選擇該選項以選擇該用戶需要消失),但可見性更改不會執行。我在這裏錯過了什麼?

如果我巢if語句是由以前的人認爲,這裏就是我有:

private void radioSelectButton_Click(object sender, EventArgs e) 
    { 
     if (pteriRadio.Checked) // Selecting avatar to be displayed from here on out. 
     //This avatar will also be displayed on the game board. 
     { 
      pteriBox1.Visible = true; 
      xweetokBox1.Visible = false; 
      ixiBox1.Visible = false; 
      label1.Text = ("Pteri Inventory"); 
      player1avatar = "pteri"; 
      if (xweetokRadio.Checked) 
      { 
       xweetokBox1.Visible = true; 
       pteriBox1.Visible = false; 
       ixiBox1.Visible = false; 
       label1.Text = ("Xweetok Inventory"); 
       player1avatar = "xweetok"; 

       if (ixiRadio.Checked) 
       { 
        ixiBox1.Visible = true; 
        pteriBox1.Visible = false; 
        xweetokBox1.Visible = false; 
        label1.Text = ("Ixi Inventory"); 
        player1avatar = "ixi"; 
       } 
       characterSelectBox.Visible = false; 
       radioSelectButton.Visible = false; 
       characterSelectBox2.Visible = true; 
       radioSelectButton2.Visible = true; 
      } 
     } 
    } 

現在,不僅不可見的物品不會掉了,兩個角色的選擇不顯示。

+1

這是winform,asp,silverlight,wpf還是什麼? – Servy

回答

-1

您需要Invalidate表單才能在更改屬性後重新繪製表單。假設radioSelectButton_Click方法的形式相同,則在方法結束時調用this.Invalidate()應強制重繪。

+0

在VS2010/.NET 4.0中,對於System.Windows.Form或System.Web.UI.Page,這似乎不是必需的。你認爲什麼版本/上下文'無效'將需要 – 2012-12-18 16:58:39

+0

請注意'asp.net'標籤... – tomfanning

+0

@tomfanning我已經補充說,在我意識到*一切*有相同的方法配置文件... – 2012-12-18 17:02:02

0

看起來這裏的單選按鈕可以一起檢查/取消選中。我認爲你應該爲每個條件使用單獨的if報表,而不是else if

相關問題