Quantcast
Channel: AuthorCode » Windows Controls
Viewing all articles
Browse latest Browse all 10

How to create Radio Buttons from a String Array in C#

$
0
0

This following example creates radio button controls and set their text from an array of strings programmatically.

Create radio buttons from array

  1. private void button2_Click(object sender, EventArgs e)
  2.         {
  3.             string[] string_Array = new string[3];
  4.  
  5.             string_Array[0] = "USA";
  6.             string_Array[1] = "India";
  7.             string_Array[2] = "Germany";
  8.  
  9.             System.Windows.Forms.RadioButton[] btnRadio = new System.Windows.Forms.RadioButton[3];
  10.  
  11.             for (int i = 0; i < 3; ++i)
  12.             {
  13.                 btnRadio[i] = new RadioButton();
  14.                 btnRadio[i].Text = string_Array[i];
  15.                 btnRadio[i].Location = new System.Drawing.Point(10, 30 + i * 20);
  16.                 this.Controls.Add(btnRadio[i]);
  17.             }
  18.         }

Viewing all articles
Browse latest Browse all 10

Trending Articles