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 control to a form window

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 41 42
Add control to a form window using System; using System.Windows.Forms; using System.Drawing; public class PushMe2 : Form { Button pushMeButton; public PushMe2() { pushMeButton = new Button(); pushMeButton.Text = "Push Me"; pushMeButton.Height = 66; pushMeButton.Width = 90; pushMeButton.Top = 70; pushMeButton.Left = 80; pushMeButton.Click += new EventHandler(ButtonClicked); this.Controls.Add(pushMeButton); this.Height = 240; this.Width = 240; this.StartPosition = FormStartPosition.CenterScreen; this.Visible = true; } public void ButtonClicked(object source, EventArgs e) { Button b = (Button)source; if ( b.Text == "Push Me" ) { b.Text = "Ouch"; } else { b.Text = "Push Me"; } } static void Main() { Application.Run(new PushMe2()); } }