问题描述
我在 groupBox 中有一些 radionButtons,我需要执行我可以称之为其中一个 radiobuttons.checked 已更改"的操作,或者从 radiobutton 中找出更改的索引.我试图在事件列表中找到它,但找不到合适的.
I have some radionButtons in groupBox and I need to do action what I could call "one of radiobuttons.checked changed" or find out from radiobutton what index is changed. I've tryed to find it in list of events but I couldn't find the right one.
为了更清楚:我需要知道是否存在一些handel,我将为goupBox而不是单个radioButton编写处理程序方法.我知道如何使用 radiButton.checkedChanged,但这不是我发现的..或者不同的是,我需要知道 groupBox 有哪些选项来监视这个 groupBox 内部发生的事情——我的意思是只有 groupBox 的处理程序.我正在寻找处理程序在组框中发生了什么事"或类似的情况(如果存在).
To make it more clear: I need to know if exist some handel for what I'll write handler method for the goupBox not for single radioButton. I know how to use radiButton.checkedChanged, but it's not what I'm finding .. Or differently I need to know what options have the groupBox in monitoring what happens inside this groupBox - I mean only the handlers for the groupBox. I'm finding handler "in the group box is something happens" or simimilar if any exist.
它位于 Visual Studio 2012 的 WFA(Windows 演示应用程序)中.
It's in WFA (Windows Presentation Application) in Visual studio 2012.
推荐答案
我认为您要做的是将所有 RadioButtons 的 CheckedChanged 事件连接到同一个处理程序.
I think what you want to do is wire up all of the RadioButtons' CheckedChanged event to the same handler.
public Form1()
{
radioButton1.CheckedChanged += new EventHandler(radioButtons_CheckedChanged);
radioButton2.CheckedChanged += new EventHandler(radioButtons_CheckedChanged);
// ...
}
private void radioButtons_CheckedChanged (object sender, EventArgs e)
{
RadioButton radioButton = sender as RadioButton;
if (radioButton1.Checked)
{
// Do stuff
}
else if (radioButton2.Checked)
{
// Do other stuff
}
}
这篇关于C# 中带有单选按钮的 groupBox 的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!