c# winform之多个控件统一事件处理程序

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
namespace WindowsApplication1
{
    //手工编写winform
    class test : Form
    {

        //测试control自带的基方法与事件对应的方法执行情况(各是否执行及执行的次序)
        RadioButton rb1;
        RadioButton rb2;
        RadioButton rb3;
        string[] str ={"radio1","radio2","radio3" };
        public test()
        {
            rb1 = new RadioButton();
            rb1.Text = "radio1";
            rb1.Location = new Point(10, 10);
            rb1.Size = new Size(10, 10);
            rb1.Parent = this;

            rb2 = new RadioButton();
            rb2.Text = "radio2";
            rb2.Location = new Point(10, 40);
            rb2.Size = new Size(10, 10);
            rb2.Parent = this;

            rb3 = new RadioButton();
            rb3.Text = "radio3";
            rb3.Location = new Point(10, 70);
            rb3.Size = new Size(10, 10);
            rb3.Parent = this;

          //三个单选按钮纳入一个事件处理程序
          rb1.CheckedChanged+=new EventHandler(rb1_CheckedChanged);
          rb2.CheckedChanged += new EventHandler(rb1_CheckedChanged);
          rb3.CheckedChanged += new EventHandler(rb1_CheckedChanged);
        }

        //在统一事件处理程序中,判断发起事件的是不同的单选按钮
        //通过controls哈哈,controls[i]
        private void rb1_CheckedChanged(object sender, EventArgs e)
        {
            for(int i=0;i
            {
                if ((RadioButton)sender == Controls[i])
                {
                    if (Controls[i].Text== str[i])
                    {
                        Label lb1 = new Label();

                    }
                }

              
            }
         }

        //经查看control类没有对应控件radiobutton的oncheckedchanged的方法
        //protected override void onch
        public static void Main()
       {
           Application.Run(new test());
       }
    }
           
        

    
 }