using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; /// /// Bjørn-Rune's løsningsforslag, laboppgave 3 og 4 GUI programmering /// Fine hacks her inne :] /// public class Lengthconv : System.Windows.Forms.Form { private System.Windows.Forms.TextBox FraVerdi; private System.Windows.Forms.TextBox TilVerdi; private System.Windows.Forms.Button Konverter; private System.Windows.Forms.Label labelFra; private System.Windows.Forms.Label labelTil; private IContainer components; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem yardMenu; private System.Windows.Forms.MenuItem meterMenu; private System.Windows.Forms.MenuItem fileMenu; private System.Windows.Forms.MenuItem exitMenu; private System.Windows.Forms.MenuItem optionsMenu; private TableLayoutPanel tableLayoutPanel1; private TextBox FraVerdi2; private MaskedTextBox maskedTextBox1; private ToolTip toolTip1; private StatusStrip statusStrip1; private ToolStripStatusLabel statusLinjeLabel; private System.Windows.Forms.ErrorProvider errorProvider1; public Lengthconv() { // // Required for Windows Form Designer support // InitializeComponent(); this.errorProvider1 = new System.Windows.Forms.ErrorProvider(); this.yardMenu.Checked = Y_to_M; this.FraVerdi.Validating += new System.ComponentModel.CancelEventHandler(this.FraVerdi_Validating); this.FraVerdi.Validated += new System.EventHandler(this.FraVerdi_Validated); this.meterMenu.Checked = M_to_Y; this.errorProvider1.ContainerControl = this; this.Closing += new System.ComponentModel.CancelEventHandler(this.Lengthconv_Closing); // // TODO: Add any constructor code after InitializeComponent call // } /// /// 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.components = new System.ComponentModel.Container(); this.FraVerdi = new System.Windows.Forms.TextBox(); this.TilVerdi = new System.Windows.Forms.TextBox(); this.Konverter = new System.Windows.Forms.Button(); this.labelFra = new System.Windows.Forms.Label(); this.labelTil = new System.Windows.Forms.Label(); this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components); this.fileMenu = new System.Windows.Forms.MenuItem(); this.exitMenu = new System.Windows.Forms.MenuItem(); this.optionsMenu = new System.Windows.Forms.MenuItem(); this.yardMenu = new System.Windows.Forms.MenuItem(); this.meterMenu = new System.Windows.Forms.MenuItem(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.FraVerdi2 = new System.Windows.Forms.TextBox(); this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusLinjeLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.tableLayoutPanel1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // // FraVerdi // this.FraVerdi.Location = new System.Drawing.Point(77, 3); this.FraVerdi.Name = "FraVerdi"; this.FraVerdi.Size = new System.Drawing.Size(100, 20); this.FraVerdi.TabIndex = 1; this.FraVerdi.Text = "0"; // // TilVerdi // this.TilVerdi.Location = new System.Drawing.Point(77, 119); this.TilVerdi.Name = "TilVerdi"; this.TilVerdi.Size = new System.Drawing.Size(100, 20); this.TilVerdi.TabIndex = 9; this.TilVerdi.TabStop = false; this.TilVerdi.Text = "0"; // // Konverter // this.Konverter.Location = new System.Drawing.Point(77, 152); this.Konverter.Name = "Konverter"; this.Konverter.Size = new System.Drawing.Size(75, 23); this.Konverter.TabIndex = 4; this.Konverter.Text = "Konverter!"; this.Konverter.Click += new System.EventHandler(this.Konverter_Click); // // labelFra // this.labelFra.Location = new System.Drawing.Point(3, 0); this.labelFra.Name = "labelFra"; this.labelFra.Size = new System.Drawing.Size(56, 20); this.labelFra.TabIndex = 4; this.labelFra.Text = "Yards"; // // labelTil // this.labelTil.Location = new System.Drawing.Point(3, 116); this.labelTil.Name = "labelTil"; this.labelTil.Size = new System.Drawing.Size(56, 20); this.labelTil.TabIndex = 5; this.labelTil.Text = "Meter"; // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.fileMenu, this.optionsMenu}); // // fileMenu // this.fileMenu.Index = 0; this.fileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.exitMenu}); this.fileMenu.Text = "File"; // // exitMenu // this.exitMenu.Index = 0; this.exitMenu.Text = "Exit"; this.exitMenu.Click += new System.EventHandler(this.exitMenu_Click); // // optionsMenu // this.optionsMenu.Index = 1; this.optionsMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.yardMenu, this.meterMenu}); this.optionsMenu.Text = "Options"; // // yardMenu // this.yardMenu.Index = 0; this.yardMenu.Text = "Yards"; this.yardMenu.Click += new System.EventHandler(this.yardMenu_Click); // // meterMenu // this.meterMenu.Index = 1; this.meterMenu.Text = "Meters"; this.meterMenu.Click += new System.EventHandler(this.meterMenu_Click); // // tableLayoutPanel1 // this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.AutoSize = true; this.tableLayoutPanel1.ColumnCount = 2; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 32.05128F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 67.94872F)); this.tableLayoutPanel1.Controls.Add(this.Konverter, 1, 4); this.tableLayoutPanel1.Controls.Add(this.FraVerdi, 1, 0); this.tableLayoutPanel1.Controls.Add(this.labelFra, 0, 0); this.tableLayoutPanel1.Controls.Add(this.FraVerdi2, 1, 1); this.tableLayoutPanel1.Controls.Add(this.TilVerdi, 1, 3); this.tableLayoutPanel1.Controls.Add(this.labelTil, 0, 3); this.tableLayoutPanel1.Controls.Add(this.maskedTextBox1, 1, 2); this.tableLayoutPanel1.Location = new System.Drawing.Point(24, 12); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 5; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 32F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 51F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(234, 182); this.tableLayoutPanel1.TabIndex = 6; // // FraVerdi2 // this.FraVerdi2.AcceptsReturn = true; this.FraVerdi2.Location = new System.Drawing.Point(77, 36); this.FraVerdi2.Name = "FraVerdi2"; this.FraVerdi2.Size = new System.Drawing.Size(100, 20); this.FraVerdi2.TabIndex = 2; this.FraVerdi2.Text = "0"; this.FraVerdi2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.FraVerdi2_KeyPress_1); this.FraVerdi2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FraVerdi2_KeyDown); // // maskedTextBox1 // this.maskedTextBox1.Location = new System.Drawing.Point(77, 68); this.maskedTextBox1.Mask = "#99,999.99"; this.maskedTextBox1.Name = "maskedTextBox1"; this.maskedTextBox1.Size = new System.Drawing.Size(100, 20); this.maskedTextBox1.TabIndex = 3; this.maskedTextBox1.Text = "0"; this.maskedTextBox1.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals; this.maskedTextBox1.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.maskedTextBox1_MaskInputRejected); this.maskedTextBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.maskedTextBox1_KeyDown); // // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.statusLinjeLabel}); this.statusStrip1.Location = new System.Drawing.Point(0, 234); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Size = new System.Drawing.Size(292, 22); this.statusStrip1.TabIndex = 7; this.statusStrip1.Text = "statusStrip1"; // // statusLinjeLabel // this.statusLinjeLabel.Name = "statusLinjeLabel"; this.statusLinjeLabel.Size = new System.Drawing.Size(111, 17); this.statusLinjeLabel.Text = "FraVerdi boks er aktiv"; // // Lengthconv // this.AcceptButton = this.Konverter; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 256); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.tableLayoutPanel1); this.Menu = this.mainMenu1; this.Name = "Lengthconv"; this.Text = "LengthConverter1"; this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Lengthconv()); } private bool Y_to_M = true; private bool M_to_Y = false; private void meterMenu_Click(object sender, System.EventArgs e) { meterMenu.Checked = true; yardMenu.Checked = false; labelFra.Text = "Meter"; labelTil.Text = "Yards"; Y_to_M = false; M_to_Y = true; } private void yardMenu_Click(object sender, System.EventArgs e) { meterMenu.Checked = false; yardMenu.Checked = true; labelFra.Text = "Yards"; labelTil.Text = "Meter"; Y_to_M = true; M_to_Y = false; } // private void Yard_to_Meters_CheckedChanged(object sender, System.EventArgs e) // { // Y_to_M = true; // M_to_Y = false; // // } // // private void Meters_to_Yards_CheckedChanged(object sender, System.EventArgs e) // { // Y_to_M = false; // M_to_Y = true; // } private void Konverter_Click(object sender, System.EventArgs e) { double fra = double.Parse(FraVerdi.Text); if (FraVerdi.Text == "0") { if (FraVerdi2.Text != "0") { fra = double.Parse(FraVerdi2.Text); } if (maskedTextBox1.Text != "0"){ fra = double.Parse(maskedTextBox1.Text); } } double til = 0; if (Y_to_M == true) til = fra * 1.094; else til = fra * 0.9144; TilVerdi.Text = til.ToString(); } static bool LegalChars(char ch) { // Tillat kun siffer og backspace int keyInt = (int)ch; if (Char.IsDigit(ch)) return false; //Dvs. ok, tegn vises i tekstboks. else if (keyInt == (int)Keys.Back) return false; else return true; } private void FraVerdi_Validating(object sender, System.ComponentModel.CancelEventArgs e) { String s = FraVerdi.Text; bool onlyDigits = true; for (int i=0;i