/* * Hello 585 example in Windows Forms C# * useing Visual Studio .NET designer. * This file is a work in progress. * * Mike Barnes 10/9/02 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Hello585 { /// /// Summary description for Hello585. /// public class Hello585 : System.Windows.Forms.Form { String currentColor, currentFont; // store current values ToolTip toolTip; // form's tooltip object private Author author; // UI components private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.Panel panel; private System.Windows.Forms.MenuItem fontMenu; private System.Windows.Forms.MenuItem arialMenuItem; private System.Windows.Forms.MenuItem timesMenuItem; private System.Windows.Forms.MenuItem courierMenuItem; private System.Windows.Forms.MenuItem helpMenu; private System.Windows.Forms.MenuItem usageMenuItem; private System.Windows.Forms.MenuItem authorMenuItem; private System.Windows.Forms.Label statusLine; private System.Windows.Forms.Panel buttonPanel; private System.Windows.Forms.RadioButton greenButton; private System.Windows.Forms.RadioButton blueButton; private System.Windows.Forms.RadioButton redButton; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Hello585() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // author = new Author(); currentColor = " default "; currentFont = " default "; // create and set tool tips toolTip = new ToolTip(); toolTip.SetToolTip(buttonPanel, "buttons set the foreground color"); toolTip.SetToolTip(panel, "click in this panel to show greeting"); toolTip.SetToolTip(statusLine, "displays current color and font"); } /// /// 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() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Hello585)); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.fontMenu = new System.Windows.Forms.MenuItem(); this.arialMenuItem = new System.Windows.Forms.MenuItem(); this.timesMenuItem = new System.Windows.Forms.MenuItem(); this.courierMenuItem = new System.Windows.Forms.MenuItem(); this.helpMenu = new System.Windows.Forms.MenuItem(); this.usageMenuItem = new System.Windows.Forms.MenuItem(); this.authorMenuItem = new System.Windows.Forms.MenuItem(); this.panel = new System.Windows.Forms.Panel(); this.statusLine = new System.Windows.Forms.Label(); this.buttonPanel = new System.Windows.Forms.Panel(); this.blueButton = new System.Windows.Forms.RadioButton(); this.greenButton = new System.Windows.Forms.RadioButton(); this.redButton = new System.Windows.Forms.RadioButton(); this.buttonPanel.SuspendLayout(); this.SuspendLayout(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.fontMenu, this.helpMenu}); // // fontMenu // this.fontMenu.Index = 0; this.fontMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.arialMenuItem, this.timesMenuItem, this.courierMenuItem}); this.fontMenu.Text = "Font"; // // arialMenuItem // this.arialMenuItem.Index = 0; this.arialMenuItem.RadioCheck = true; this.arialMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlA; this.arialMenuItem.Text = "Arial 10pt"; this.arialMenuItem.Click += new System.EventHandler(this.arialMenuItem_Click); // // timesMenuItem // this.timesMenuItem.Index = 1; this.timesMenuItem.RadioCheck = true; this.timesMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlT; this.timesMenuItem.Text = "Times 14 pt"; this.timesMenuItem.Click += new System.EventHandler(this.timesMenuItem_Click); // // courierMenuItem // this.courierMenuItem.Index = 2; this.courierMenuItem.RadioCheck = true; this.courierMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlC; this.courierMenuItem.Text = "Courier 18pt"; this.courierMenuItem.Click += new System.EventHandler(this.courierMenuItem_Click); // // helpMenu // this.helpMenu.Index = 1; this.helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.usageMenuItem, this.authorMenuItem}); this.helpMenu.Text = "Help"; // // usageMenuItem // this.usageMenuItem.Index = 0; this.usageMenuItem.Text = "Usage"; this.usageMenuItem.Click += new System.EventHandler(this.usageMenuItem_Click); // // authorMenuItem // this.authorMenuItem.Index = 1; this.authorMenuItem.Text = "Author"; this.authorMenuItem.Click += new System.EventHandler(this.authorMenuItem_Click); // // panel // this.panel.BackColor = System.Drawing.Color.White; this.panel.Cursor = System.Windows.Forms.Cursors.Cross; this.panel.Dock = System.Windows.Forms.DockStyle.Fill; this.panel.Location = new System.Drawing.Point(0, 0); this.panel.Name = "panel"; this.panel.Size = new System.Drawing.Size(492, 248); this.panel.TabIndex = 0; this.panel.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panelMouseUp); this.panel.Paint += new System.Windows.Forms.PaintEventHandler(this.panel_Paint); // // statusLine // this.statusLine.BackColor = System.Drawing.SystemColors.Control; this.statusLine.Dock = System.Windows.Forms.DockStyle.Bottom; this.statusLine.Location = new System.Drawing.Point(0, 248); this.statusLine.Name = "statusLine"; this.statusLine.Size = new System.Drawing.Size(492, 25); this.statusLine.TabIndex = 1; this.statusLine.Text = "Select a color and font than click in the white panel"; this.statusLine.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // buttonPanel // this.buttonPanel.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255))); this.buttonPanel.Controls.Add(this.blueButton); this.buttonPanel.Controls.Add(this.greenButton); this.buttonPanel.Controls.Add(this.redButton); this.buttonPanel.Dock = System.Windows.Forms.DockStyle.Left; this.buttonPanel.Location = new System.Drawing.Point(0, 0); this.buttonPanel.Name = "buttonPanel"; this.buttonPanel.Size = new System.Drawing.Size(96, 248); this.buttonPanel.TabIndex = 2; // // blueButton // this.blueButton.Appearance = System.Windows.Forms.Appearance.Button; this.blueButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255))); this.blueButton.Cursor = System.Windows.Forms.Cursors.Hand; this.blueButton.Location = new System.Drawing.Point(8, 164); this.blueButton.Name = "blueButton"; this.blueButton.Size = new System.Drawing.Size(80, 25); this.blueButton.TabIndex = 2; this.blueButton.Text = "blue"; this.blueButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.blueButton.CheckedChanged += new System.EventHandler(this.blueButton_CheckedChanged); // // greenButton // this.greenButton.Appearance = System.Windows.Forms.Appearance.Button; this.greenButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(192))); this.greenButton.Cursor = System.Windows.Forms.Cursors.Hand; this.greenButton.Location = new System.Drawing.Point(8, 112); this.greenButton.Name = "greenButton"; this.greenButton.Size = new System.Drawing.Size(80, 25); this.greenButton.TabIndex = 1; this.greenButton.Text = "green"; this.greenButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.greenButton.CheckedChanged += new System.EventHandler(this.greenButton_CheckedChanged); // // redButton // this.redButton.Appearance = System.Windows.Forms.Appearance.Button; this.redButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192))); this.redButton.Cursor = System.Windows.Forms.Cursors.Hand; this.redButton.Location = new System.Drawing.Point(8, 60); this.redButton.Name = "redButton"; this.redButton.Size = new System.Drawing.Size(80, 25); this.redButton.TabIndex = 0; this.redButton.Text = "red"; this.redButton.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.redButton.CheckedChanged += new System.EventHandler(this.redButton_CheckedChanged); // // Hello585 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackColor = System.Drawing.SystemColors.ControlDarkDark; this.ClientSize = new System.Drawing.Size(492, 273); this.Controls.Add(this.buttonPanel); this.Controls.Add(this.panel); this.Controls.Add(this.statusLine); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Menu = this.mainMenu1; this.Name = "Hello585"; this.Text = "Hello CS 585"; this.Load += new System.EventHandler(this.Hello585_Load); this.buttonPanel.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Hello585()); } private void Hello585_Load(object sender, System.EventArgs e) { } private void showStatus() { statusLine.Text = "Current color is" + currentColor + "current font is" + currentFont + "."; } private void panel_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; // the location is in Hello585 form's client area g.DrawString("Hi CS585", panel.Font, new SolidBrush(panel.ForeColor),175, 100); } private void panelMouseUp(object sender, MouseEventArgs mea) { Graphics g = panel.CreateGraphics(); g.DrawString("Hi CS585", panel.Font, new SolidBrush(panel.ForeColor), mea.X, mea.Y); g.Dispose(); // statusLine.Text = "panel mouse up"; // statusLine as easy debugger } private void redButton_CheckedChanged(object sender, System.EventArgs e) { panel.ForeColor = Color.Red; currentColor = " Red "; showStatus(); } private void greenButton_CheckedChanged(object sender, System.EventArgs e) { panel.ForeColor = Color.Green; currentColor = " Green "; showStatus(); } private void blueButton_CheckedChanged(object sender, System.EventArgs e) { panel.ForeColor = Color.Blue; currentColor = " Blue "; showStatus(); } private void arialMenuItem_Click(object sender, System.EventArgs e) { panel.Font = new Font("Arial", 10); currentFont = " Arial 10 pt "; showStatus(); } private void timesMenuItem_Click(object sender, System.EventArgs e) { panel.Font = new Font("Times New Roman", 14); currentFont = " Times 14 pt "; showStatus(); } private void courierMenuItem_Click(object sender, System.EventArgs e) { panel.Font = new Font("Courier New", 18); currentFont = " Courier 18 pt "; showStatus(); } private void authorMenuItem_Click(object sender, System.EventArgs e) { author.Show(); // for modal dialog use ShowDialog(); } private void usageMenuItem_Click(object sender, System.EventArgs e) { MessageBox.Show("usage dialog not implemented see author", "Usage", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }