MonCheckBox.Checked = true;
("MonCheck"+"Box"+"10").Checked = true;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionforeach( Control ctrl in this.Controls ) { if ( ctrl.Tag == "??" ) //blabla }
foreach( Control ctrl in this.Controls ) { if(ctrl.GetType() == typeof(TextBox)) { if ( ctrl.Tag == "??" ) //blabla } }
public Form1( ) { InitializeComponent( ); CheckBox mainCheckBox = new CheckBox( ); mainCheckBox.Parent = this; mainCheckBox.Location = new Point( 10, 10 ); mainCheckBox.CheckedChanged += delegate { for( int i = 0; i < 10; i++ ) { ( ( CheckBox )this.Controls[ "checkbox" + i ] ).Checked = mainCheckBox.Checked; } }; //mainCheckBox.CheckedChanged += delegate // Autre solution sans nom. //{ // foreach( Control ctrl in this.Controls ) // { // CheckBox checkbox = ctrl as CheckBox; // if ( checkbox != null && checkbox != mainCheckBox ) // { // checkbox.Checked = mainCheckBox.Checked; // } // } //}; for ( int i = 0; i < 10; i++ ) { CheckBox checkbox = new CheckBox( ); checkbox.Parent = this; checkbox.Location = new Point( 10, 40 + 20 * i ); checkbox.Name = "checkbox" + i; } }
// CheckBox1 étant un checkbox existant et inclus dans la form. String s = "CheckBox1"; CheckBox cb.name = s; //Ici, j'associerais cb à CheckBox1, sorte d'alias. cb.Checked = true;