C# 中带有单选按钮的 groupBox 的事件处理程序

Event handler for groupBox with radioButtons in C#(C# 中带有单选按钮的 groupBox 的事件处理程序)
本文介绍了C# 中带有单选按钮的 groupBox 的事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)