/[OhmsLawCalc]/trunk/OhmsLawCalc/UI/CircuitValue.cs
ViewVC logotype

Contents of /trunk/OhmsLawCalc/UI/CircuitValue.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (show annotations) (download)
Wed Jan 29 06:39:26 2014 UTC (5 years, 11 months ago) by william
File size: 2541 byte(s)

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using libOhmsLawCalc;
10
11 namespace OhmsLawCalc.UI
12 {
13 public partial class CircuitValue : UserControl
14 {
15 const int DefaultValueIndex = 4;
16 public CircuitValue()
17 {
18 InitializeComponent();
19 ValueType = OhmsLawValueType.None;
20 }
21
22 private OhmsLawValueType _ValueType;
23 [Browsable(true)]
24 public OhmsLawValueType ValueType
25 {
26 get { return _ValueType; }
27 set { _ValueType = value; }
28 }
29 private void CircuitValue_Load(object sender, EventArgs e)
30 {
31 comboUnits.Items.Clear();
32 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Pico));
33 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Nano));
34 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Micro));
35 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Milli));
36 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Default));
37 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Kilo));
38 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Mega));
39 comboUnits.Items.Add(CreateUnitString(OhmsLawUnitType.Giga));
40
41 comboUnits.Text = comboUnits.Items[DefaultValueIndex].ToString();
42 }
43
44 private string CreateUnitString(OhmsLawUnitType unit)
45 {
46 if (unit == OhmsLawUnitType.Default)
47 {
48 return string.Format("{0}", CreateValueTypeString());
49 }
50 else
51 {
52 return string.Format("{0} {1}", unit.ToString(), CreateValueTypeString());
53 }
54 }
55
56 private string CreateValueTypeString()
57 {
58 switch (this.ValueType)
59 {
60 case OhmsLawValueType.Power: return "Watts";
61 case OhmsLawValueType.Current: return "Amps";
62 case OhmsLawValueType.Resistance: return "Ohms";
63 case OhmsLawValueType.Voltage: return "Volts";
64 case OhmsLawValueType.None: return "None";
65 default:
66 throw new InvalidOperationException(string.Format("Value: 0x{0:x8} is not defined in OhmsLawValueType", (uint)this.ValueType));
67 }
68 }
69 }
70 }

  ViewVC Help
Powered by ViewVC 1.1.22