Radio button checked changed event fires twice

后端 未结 7 1016
梦谈多话
梦谈多话 2020-12-03 16:52

Please read my question its not a duplicate one.

I\'ve three radio buttons on windows form and all these buttons have common \'CheckedChanged\' event associated. Whe

7条回答
  •  青春惊慌失措
    2020-12-03 17:27

    You could set the AutoCheck property true for each RadioButton then catch the Click event instead of the CheckChanged event. This would ensure that only one event is fired, and the logic in the handler can cast the sender to type RadioButton if needed to process the click. Often the cast can be avoided if the handler logic is simple. Here is an example which handles three controls, rbTextNumeric, rbTextFixed and rbTextFromFile:

            private void rbText_Click(object sender, EventArgs e)
        {
           flowLayoutPanelTextNumeric.Enabled = rbTextNumeric.Checked;
           txtBoxTextFixed.Enabled = rbTextFixed.Checked;
           flowLayoutPanelTextFromFile.Enabled = rbTextFromFile.Checked;
        }
    

提交回复
热议问题