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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
//
// The prototypical functional GUI application, the counter.
//
// To compile: csc /t:library ui.cs
//
using System;
using System.Windows.Forms;
public class UITest : Form {
private Button upButton;
private Button downButton;
private Label countLabel;
private int count;
public UITest() {
upButton = new Button();
upButton.Text = "Up";
Controls.Add(upButton);
downButton = new Button();
downButton.Text = "Down";
downButton.Location = new System.Drawing.Point (0,50);
Controls.Add(downButton);
countLabel = new Label();
countLabel.Text = count.ToString();
countLabel.Location = new System.Drawing.Point (0,30);
countLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
Controls.Add(countLabel);
Text = "WinForms example";
Height = 100;
Width = 100;
}
public void IncCount() {
count++;
countLabel.Text = count.ToString();
}
public void DecCount() {
count--;
countLabel.Text = count.ToString();
}
public void AddHandlerUp(System.EventHandler h) {
upButton.Click += h;
}
public void AddHandlerDown(System.EventHandler h) {
downButton.Click += h;
}
public void RunIt() {
Application.Run(this);
}
/*
public void KickOff(System.EventHandler h) {
button1.Click += h;
Application.Run(this);
}
private void button1_click(object sender, EventArgs e) {
MessageBox.Show("button1 clicked");
}
*/
}
/*
public class TestApp {
public static void Main(string[] args) {
Application.Run(new SampleApp());
}
}
*/
|