/* * Introductory Hello CS585 project in Windows Forms C# * uses console output to show program execution. * * Mike Barnes 9/22/02 */ using System; using System.Drawing; using System.Windows.Forms; class HelloWindowsForm : Form { readonly Button b; string bLabel; bool bState; public static void Main() { System.Console.WriteLine("Main: enter"); Application.Run(new HelloWindowsForm()); System.Console.WriteLine("Main: leave"); } public HelloWindowsForm() { System.Console.WriteLine("HelloWindowsForm: enter"); Width = 100; // set size of form Height = 50; b = new Button(); b.Parent = this; bLabel = "Hello CS 585 !"; bState = true; b.Text= bLabel; b.Dock = DockStyle.Fill; b.Click += new EventHandler(ButtonOnClick); System.Console.WriteLine("HelloWindowsForm: leave"); } // process button clicks void ButtonOnClick(object obj, EventArgs e) { System.Console.WriteLine("ButtonOnClick: enter"); if (bState) b.Text = "press me again"; else b.Text = "Hello CS 585 !"; bState = !bState; System.Console.WriteLine("ButtonOnClick: leave, bState = " + bState.ToString()); } }