Advertisement
dantepw

C# 2 - Ativar/desativar componentes com um RadioButton

Dec 29th, 2014
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Tutorial
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.  
  23.         }
  24.  
  25.         private void radioButton1_Click(object sender, EventArgs e)
  26.         {
  27.             Desativar(this, "textBox1");
  28.         }
  29.  
  30.         private void radioButton2_Click(object sender, EventArgs e)
  31.         {
  32.             Desativar(this, "textBox2");
  33.         }
  34.  
  35.         private void radioButton3_Click(object sender, EventArgs e)
  36.         {
  37.             Desativar(this, "textBox3");
  38.         }
  39.  
  40.         private void Desativar(Form f, String nomeComponente)
  41.         {
  42.             foreach (Control c in f.Controls)
  43.             {
  44.                 if (c is TextBox)
  45.                 {
  46.                     if (c.Name == nomeComponente)
  47.                         c.Enabled = true;
  48.                     else
  49.                         c.Enabled = false;
  50.                 }
  51.             }
  52.         }
  53.  
  54.  
  55.  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement