开发者

Toggling Radio Buttons In WinForms

开发者 https://www.devze.com 2023-02-03 04:58 出处:网络
This is what I\'m doing and it results in a stack overflow because it just switches back and forth forever.

This is what I'm doing and it results in a stack overflow because it just switches back and forth forever.

    private void radioButtonA_CheckedChanged(object sender, EventArgs e)
    {
        radioButtonB.Checked = !radioButtonB.Checked;
    }

 开发者_如何学运维   private void radioButtonB_CheckedChanged(object sender, EventArgs e)
    {
        radioButtonA.Checked = !radioButtonA.Checked;
    }

There has to be a better way to do this...


try commenting out all of your code and see if it works the way you want. you don't have to uncheck the other radio buttons in code


Is it toggling of "One" radio button what you were trying to do? If so, I tried this, and it works for me:

Set the Radio Button AutoCheck property to FALSE.

Create a "Click" event for the Radio Button.

In the Click Event Handler for the Radio Button paste the code:

radioButton.Checked = !radioButton.Checked;

I hope this helps.


You can disable the Event in the code before changing the Checked value, then add it again immediately afterwards.

0

精彩评论

暂无评论...
验证码 换一张
取 消