Holey_yan

[C#] ControlAddHandler

May 15th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace ControlAddHandler
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void Form1_Load(object sender, EventArgs e)
  20.         {
  21.             foreach (Control control in this.Controls)
  22.             {
  23.                 if (control is RadioButton)
  24.                 {
  25.                     ((RadioButton)control).CheckedChanged += radioButton_CheckedChanged;
  26.                 }
  27.             }
  28.         }
  29.  
  30.         private void radioButton_CheckedChanged(object sender, EventArgs e)
  31.         {
  32.             switch (int.Parse(((RadioButton)sender).Name.Replace("radioButton", string.Empty)))
  33.             {
  34.                 case 1:
  35.                 case 2:
  36.                 case 6:
  37.                 case 7:
  38.                 case 9:
  39.                 case 11:
  40.                 case 12:
  41.                     comboBox1.Enabled = true; break;
  42.                 default:
  43.                     comboBox1.Enabled = false; break;
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment