0

i have 3 radio buttons:

rbtPercentualmedioanual
rbtPercentualmensal
rbtValorfixo

I would like to change options events for textbox1 according choosed option

If chose rbtValorfixo, It will uncomment:

private void textbox1_TextChanged(object sender, EventArgs e)
{
    //substituipontovirgula_textBox(sender as TextBox, e);
}

private void textbox1_Leave(object sender, EventArgs e)
{
    //formatamoeda_textBox(sender as TextBox, e);
}
private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
{
    //numeropontoouvirgula_textBox(sender as TextBox, e);
    formatarporcentagem_textBox(sender as TextBox, e);
}

and will comment

private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        numeropontoouvirgula_textBox(sender as TextBox, e);
        //formatarporcentagem_textBox(sender as TextBox, e);
    }

If choose option rbtPercentualmedioanual or rbtPercentualmensal, it will comment:

private void textbox1_TextChanged(object sender, EventArgs e)
{
    substituipontovirgula_textBox(sender as TextBox, e);
}

private void textbox1_Leave(object sender, EventArgs e)
{
    formatamoeda_textBox(sender as TextBox, e);
}
private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
{
    numeropontoouvirgula_textBox(sender as TextBox, e);
    //formatarporcentagem_textBox(sender as TextBox, e);
}

and will uncomment: formatarporcentagem_textBox

private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
{
    //numeropontoouvirgula_textBox(sender as TextBox, e);
    //formatarporcentagem_textBox(sender as TextBox, e);
}

i dont know how comment/uncomment keypress, textchanged or focusleave event using radiobutton check, only say how, not need make all, i can do it, but i have to know if its possible and if is, how ?

Thanks

4

3 回答 3

2

您可以通过 radioButton.Checked 属性确定是否选中了单选按钮或复选框。

在您的情况下,它将是这样的:

private void textbox1_TextChanged(object sender, EventArgs e)
{
    if(!rbtValorfixo.Checked)
      substituipontovirgula_textBox(sender as TextBox, e);
}

或者:

private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if(rbtValorfixo.Checked)
      numeropontoouvirgula_textBox(sender as TextBox, e);
    else
      formatarporcentagem_textBox(sender as TextBox, e);
}

等等。

于 2013-04-18T08:29:29.370 回答
0

你可能想使用这样的东西?不确定,因为它很不清楚你想说什么。private void Operation_Changed(object sender, EventArgs e) { RadioButton rbt = sender as RadioButton; 如果(btn!= null)

            {
                case "rbtPercentualmedioanual":
                    _operation = new example2();
                    example1.Visible = true;
                    example2.Visible = true;
                    example3.Visible = false;

                    return;

                case "rbtPercentualmensal":
                    _operation = new example3();
                    example1.Visible = true;
                    example2.Visible = true;
                    example3.Visible = false;

                    return;

                case "rbtValorfixo":
                    _operation = new example1();
                    example1.Visible = true;
                    example2.Visible = true;
                    example3.Visible = false;


                default:
                    break;

并将其更改为您要显示的内容

于 2013-04-18T08:34:57.097 回答
0

您不需要注释或取消注释代码。在编程语言中,您需要注意正确的结构。

在这个相当简单的情况下,您只需要一个“if”块。

这可能会有所帮助

于 2013-04-18T08:30:03.457 回答