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;
            }
        }
    }

现在,不仅可见项目不会交换,两个角色选择也不会显示。

4

2 回答 2

0

看起来这里的单选按钮可以一起选中/取消选中。if我认为您应该为每个条件使用单独的语句,而不是else if.

于 2012-12-18T16:58:37.110 回答
-1

Invalidate更改属性后,您需要重新绘制表单。假设radioSelectButton_Click方法是相同的形式,this.Invalidate()在方法结束时调用应该强制重绘。

于 2012-12-18T16:39:41.033 回答