using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; // ? using System.Drawing.Drawing2D; // LinearGradientBrush object using System.Resources; // ResourceManager object namespace Standard { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void restoreWindowState() { string stringMe = "restoreWindowState: "; try { this.Top = Model.MainFormTop; this.Left = Model.MainFormLeft; this.Width = Model.MainFormWidth; this.Height = Model.MainFormHeight; if (Model.MainFormMaximized) WindowState = FormWindowState.Maximized; } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } private void MainForm_Load(object sender, System.EventArgs e) { string stringMe = "MainForm_Load: "; try { LogFile.WriteLine(stringMe + "screen is " + SystemInformation.WorkingArea.Width.ToString() + " by " + SystemInformation.WorkingArea.Height.ToString() + " pixels"); this.Icon = new Icon(this.GetType(), "application.ico"); restoreWindowState(); this.Text = Application.ProductName + " " + Model.VersionShort; this.BackColor = Model.BackgroundColor; if (Model.Background == Model.BgType.Image) fixImage(); else this.Invalidate(); menuAbout.Text = "About " + this.Text; this.statusBar1.Panels[0].Text = DateTime.Now.ToLongTimeString(); this.statusBar1.Panels[1].Text = DateTime.Now.ToShortDateString(); this.timer1.Interval = 1000; this.timer1.Enabled = true; } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) { string stringMe = "MainForm.OnPaintBackground: "; try { if (Model.Background == Model.BgType.Gradient) { Graphics gc = pevent.Graphics; // paint from upper-left corner (0,0) to lower-right LinearGradientBrush linGrBrush = new LinearGradientBrush(new Point(0,0), new Point(this.Width, this.Height), Model.GradientColor1,Model.GradientColor2); gc.FillRectangle(linGrBrush, pevent.ClipRectangle); } else { base.OnPaintBackground(pevent); } } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } private void menuExit_Click(object sender, System.EventArgs e) { string stringMe = "menuExit_Click: "; try { this.Close(); } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } private void saveWindowState() { if (this.WindowState.Equals(FormWindowState.Maximized)) { Model.MainFormMaximized = true; } else { Model.MainFormMaximized = false; Model.MainFormTop = this.Top; Model.MainFormLeft = this.Left; Model.MainFormWidth = this.Width; Model.MainFormHeight = this.Height; } } private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { string stringMe = "MainForm_Closing: "; try { LogFile.WriteLine(stringMe + "starting"); saveWindowState(); } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } private void buttonExit_Click(object sender, System.EventArgs e) { menuExit_Click(sender,e); } private void menuAbout_Click(object sender, System.EventArgs e) { string stringMe = "menuAbout_Click: "; try { AboutForm myAboutForm = new AboutForm(); myAboutForm.ShowDialog(this); } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } private void MainForm_SizeChanged(object sender, System.EventArgs e) { string stringMe = "MainForm_SizeChanged: "; try { this.Invalidate(); } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } private void timer1_Tick(object sender, System.EventArgs e) { this.statusBar1.Panels[0].Text = DateTime.Now.ToLongTimeString(); } private void menuBgSolid_Click(object sender, System.EventArgs e) { this.BackgroundImage = null; Model.Background = Model.BgType.Solid; this.Invalidate(); } private void menuBgGradient_Click(object sender, System.EventArgs e) { this.BackgroundImage = null; Model.Background = Model.BgType.Gradient; this.Invalidate(); } private void fixImage() { this.BackgroundImage = new Bitmap(this.GetType(), "background.jpg"); this.Invalidate(); } private void menuBgImage_Click(object sender, System.EventArgs e) { Model.Background = Model.BgType.Image; fixImage(); } private void MainForm_ResizeEnd(object sender, EventArgs e) { string stringMe = "MainForm_ResizeBegin: "; try { saveWindowState(); } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } protected override void OnResize(EventArgs ea) { string stringMe = "OnResize: "; try { this.Invalidate(); this.Update(); base.OnResize(ea); } catch (Exception ex) { throw new Exception(stringMe + ex.Message); } } } // end class } // end namespace