/* ************************************************* Skrá: T203Fv5_1.cs Höfundur: Ragnar Geir Brynjólfsson. Dagsetning: 14.6.2005. Forrit sem umreiknar hraðakvarða ************************************************* */ using System; using System.Drawing; using System.Windows.Forms; public class T203Fv5_1 : Form { //Eintökun tilviksbreyta RadioButton r1 = new RadioButton(); RadioButton r2 = new RadioButton(); GroupBox g1 = new GroupBox(); TextBox t = new TextBox(); Label l = new Label(); Button b = new Button(); bool mk = true; //Smiður fyrir formið skilgreindur: public T203Fv5_1() { int BREIDD = this.ClientSize.Width-1; //Stærð stýringa stillt: t.Size = new Size(BREIDD,0); b.Size = new Size(BREIDD,20); l.Size = new Size(BREIDD,20); g1.Size= new Size(BREIDD,60); r1.Size= new Size(BREIDD,20); r2.Size= new Size(BREIDD,20); //Staðsetning stýringa stillt: r1.Location = new Point(0,10); r2.Location = new Point(0,40); t.Location = new Point(0,71); b.Location = new Point(0,91); l.Location = new Point(0,112); //Aðrir eiginleikar settir: r1.Text = "Kílómetrar í mílur."; r2.Text = "Mílur í kílómetra."; r1.Checked = true; b.Text = "Breyta"; Text="Hraðakvarðar"; //Stýringum bætt á formið: g1.Controls.Add(r1); g1.Controls.Add(r2); Controls.Add(g1); Controls.Add(t); Controls.Add(l); Controls.Add(b); //Atburðameðhöndlun tilkynnt. b.Click += new EventHandler(Smellt); r1.CheckedChanged += new EventHandler(Val); r2.CheckedChanged += new EventHandler(Val); } //Smiður endar. //Atburðameðhöndlun útfærð: void Smellt(object o, EventArgs e) { try { int i = Convert.ToInt32(t.Text); if(mk) l.Text = (i/1.609).ToString("0.##") + " mílur."; else l.Text = (i*1.609).ToString("0.##") + " kílóm."; } catch { l.Text = "Þú verður að slá inn tölu"; } } void Val (object o, EventArgs e) { if (o==r1) mk = true; else mk = false; } static void Main() { Application.Run(new T203Fv5_1()); } }