programming-examples/c-sharp/Others/Change Button text.cs

44 lines
883 B
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
Change Button text
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 = 50;
pushMeButton.Width = 96;
pushMeButton.Top = 70;
pushMeButton.Left = 70;
pushMeButton.Click += new EventHandler(ButtonClicked);
this.Controls.Add(pushMeButton);
this.Height = 250;
this.Width = 250;
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());
}
}