using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace PS7_Q1 { // // Problem Set 7, Question 1 // Program Design Exercise 20 in Chapter 9 // Written by Paul Hudak // November 6, 2006 // public class Form1 : System.Windows.Forms.Form { // these were created by the Designer private System.Windows.Forms.Label display; private System.Windows.Forms.ComboBox styleCombo; private System.Windows.Forms.Label styleLab; private System.Windows.Forms.TextBox capitalBox; private System.Windows.Forms.Label capitalLab; private System.Windows.Forms.Button FranceBut; private System.Windows.Forms.Button EnglandBut; private System.Windows.Forms.Button MexicoBut; private System.Windows.Forms.RadioButton largeRadio; private System.Windows.Forms.RadioButton smallRadio; private System.Windows.Forms.Label sizeLab; // Required designer variable. private System.ComponentModel.Container components = null; // font name as global constant const string fontName = "Ariel"; public Form1() { // Required for Windows Form Designer support InitializeComponent(); // set display font to default of large (16pt) and boldface display.Font = new Font(fontName, 16, FontStyle.Bold); // register event handlers FranceBut.Click += new EventHandler(CountryClick); EnglandBut.Click += new EventHandler(CountryClick); MexicoBut.Click += new EventHandler(CountryClick); // set up combo box options styleCombo.Items.Add("Italic"); styleCombo.Items.Add("Bold"); // set initial selected item styleCombo.SelectedItem = "Bold"; } // single event handler private void CountryClick(object sender, System.EventArgs e) { // font size determined by radio buttons int fontSize = largeRadio.Checked ? 16 : 12; // font style determined by combo box FontStyle fontStyle = (styleCombo.SelectedItem.ToString() == "Bold") ? FontStyle.Bold : FontStyle.Italic; // set display font display.Font = new Font(fontName, fontSize, fontStyle); // set display text display.Text = "The Capital of " + ((Button)sender).Text + " is " + capitalBox.Text + "."; } // Clean up any resources being used. protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.display = new System.Windows.Forms.Label(); this.styleCombo = new System.Windows.Forms.ComboBox(); this.styleLab = new System.Windows.Forms.Label(); this.capitalBox = new System.Windows.Forms.TextBox(); this.capitalLab = new System.Windows.Forms.Label(); this.FranceBut = new System.Windows.Forms.Button(); this.EnglandBut = new System.Windows.Forms.Button(); this.MexicoBut = new System.Windows.Forms.Button(); this.largeRadio = new System.Windows.Forms.RadioButton(); this.smallRadio = new System.Windows.Forms.RadioButton(); this.sizeLab = new System.Windows.Forms.Label(); this.SuspendLayout(); // // display // this.display.BackColor = System.Drawing.SystemColors.ControlLightLight; this.display.Location = new System.Drawing.Point(136, 72); this.display.Name = "display"; this.display.Size = new System.Drawing.Size(264, 72); this.display.TabIndex = 0; this.display.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.display.Click += new System.EventHandler(this.label1_Click); // // styleCombo // this.styleCombo.Location = new System.Drawing.Point(24, 112); this.styleCombo.Name = "styleCombo"; this.styleCombo.Size = new System.Drawing.Size(88, 21); this.styleCombo.TabIndex = 1; this.styleCombo.Text = "Bold"; // // styleLab // this.styleLab.Location = new System.Drawing.Point(48, 88); this.styleLab.Name = "styleLab"; this.styleLab.Size = new System.Drawing.Size(32, 23); this.styleLab.TabIndex = 2; this.styleLab.Text = "Style"; this.styleLab.Click += new System.EventHandler(this.label2_Click); // // capitalBox // this.capitalBox.Location = new System.Drawing.Point(416, 112); this.capitalBox.Name = "capitalBox"; this.capitalBox.TabIndex = 3; this.capitalBox.Text = ""; // // capitalLab // this.capitalLab.Location = new System.Drawing.Point(416, 88); this.capitalLab.Name = "capitalLab"; this.capitalLab.TabIndex = 4; this.capitalLab.Text = "Enter Capital:"; // // FranceBut // this.FranceBut.Location = new System.Drawing.Point(136, 32); this.FranceBut.Name = "FranceBut"; this.FranceBut.TabIndex = 5; this.FranceBut.Text = "France"; // // EnglandBut // this.EnglandBut.Location = new System.Drawing.Point(232, 32); this.EnglandBut.Name = "EnglandBut"; this.EnglandBut.TabIndex = 6; this.EnglandBut.Text = "England"; // // MexicoBut // this.MexicoBut.Location = new System.Drawing.Point(328, 32); this.MexicoBut.Name = "MexicoBut"; this.MexicoBut.TabIndex = 7; this.MexicoBut.Text = "Mexico"; // // largeRadio // this.largeRadio.Checked = true; this.largeRadio.Location = new System.Drawing.Point(256, 160); this.largeRadio.Name = "largeRadio"; this.largeRadio.Size = new System.Drawing.Size(72, 24); this.largeRadio.TabIndex = 8; this.largeRadio.TabStop = true; this.largeRadio.Text = "Large"; // // smallRadio // this.smallRadio.Location = new System.Drawing.Point(256, 184); this.smallRadio.Name = "smallRadio"; this.smallRadio.Size = new System.Drawing.Size(72, 24); this.smallRadio.TabIndex = 9; this.smallRadio.Text = "Small"; // // sizeLab // this.sizeLab.Location = new System.Drawing.Point(200, 176); this.sizeLab.Name = "sizeLab"; this.sizeLab.Size = new System.Drawing.Size(40, 16); this.sizeLab.TabIndex = 10; this.sizeLab.Text = "Size"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(552, 245); this.Controls.Add(this.sizeLab); this.Controls.Add(this.smallRadio); this.Controls.Add(this.largeRadio); this.Controls.Add(this.MexicoBut); this.Controls.Add(this.EnglandBut); this.Controls.Add(this.FranceBut); this.Controls.Add(this.capitalLab); this.Controls.Add(this.capitalBox); this.Controls.Add(this.styleLab); this.Controls.Add(this.styleCombo); this.Controls.Add(this.display); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion // The main entry point for the application. [STAThread] static void Main() { Application.Run(new Form1()); } // the Designer created these -- not sure why, but they can't be deleted private void label2_Click(object sender, System.EventArgs e) { } private void label1_Click(object sender, System.EventArgs e) { } } }