Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


CSharp Programming

CSharp > Code Examples

Add items to combo box

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Add items to combo box using System; using System.Drawing; using System.Windows.Forms; public class Select : Form { private Button draw = new Button(); private ComboBox color = new ComboBox(); public Select( ) { draw.Text = "Draw"; color.Text = "Choose a color"; Size = new Size(400,240); int w = 20; draw.Location = new Point(20,30); color.Location = new Point(w += 10 + color.Width, 30); color.Items.Add("Black"); color.Items.Add("Red"); color.Items.Add("Blue"); Controls.Add(draw); Controls.Add(color); draw.Click += new EventHandler(Draw_Click); } protected void Draw_Click(Object sender, EventArgs e) { if (color.SelectedItem.ToString() == "Red" ) Console.WriteLine("It is red."); else if (color.SelectedItem.ToString() == "Red") Console.WriteLine("It is Red."); else Console.WriteLine("It is blue."); } static void Main() { Application.Run(new Select()); } }