/[RomCheater]/trunk/Win32/libWin32/Win32/UI/NumericBoxBase.cs
ViewVC logotype

Annotation of /trunk/Win32/libWin32/Win32/UI/NumericBoxBase.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 220 - (hide annotations) (download)
Sat Jun 2 11:55:57 2012 UTC (8 years, 7 months ago) by william
File size: 4095 byte(s)
+ overhaul some number type controls

1 william 88 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    
10     namespace System.Windows.Forms
11     {
12 william 220 public partial class NumericBoxBase : UserControl
13 william 88 {
14 william 220 public NumericBoxBase()
15 william 88 {
16     InitializeComponent();
17     this.Value = 0;
18     this.ReadOnly = false;
19     }
20    
21 william 220 private ValueType _Value;
22     [Browsable(true)]
23     public ValueType Value
24 william 88 {
25     get { return _Value; }
26     set { _Value = value; this.Text = value.ToString(); }
27     }
28    
29     private bool _ReadOnly;
30 william 220 public bool ReadOnly
31 william 88 {
32     get { return _ReadOnly; }
33     set { _ReadOnly = value; if (_ReadOnly) { txtValueBox.Enabled = false; } else { txtValueBox.Enabled = true; } }
34     }
35     public override string Text
36     {
37     get { return txtValueBox.Text; }
38     set { txtValueBox.Text = value; }
39     }
40    
41     private void btnCopy_Click(object sender, EventArgs e) { Clipboard.SetData(DataFormats.Text, this.Text); }
42     private void btnPaste_Click(object sender, EventArgs e) { if (this.ReadOnly) return; this.Text = (string)Clipboard.GetData(DataFormats.Text); }
43     }
44    
45     #region NumericBox Extensions
46     public static class NumericBoxExtensions
47     {
48 william 220 public static byte ToByte(this NumericBoxBase val)
49 william 88 {
50     try
51     {
52     return Convert.ToByte(val.Value);
53     }
54     catch { return 0; }
55     }
56 william 220 public static sbyte ToSByte(this NumericBoxBase val)
57 william 88 {
58     try
59     {
60     return Convert.ToSByte(val.Value);
61     }
62     catch { return 0; }
63     }
64 william 220 public static Int16 ToInt16(this NumericBoxBase val)
65 william 88 {
66     try
67     {
68     return Convert.ToInt16(val.Value);
69     }
70     catch { return 0; }
71     }
72 william 220 public static Int32 ToInt32(this NumericBoxBase val)
73 william 88 {
74     try
75     {
76     return Convert.ToInt32(val.Value);
77     }
78     catch { return 0; }
79     }
80 william 220 public static Int64 ToInt64(this NumericBoxBase val)
81 william 88 {
82     try
83     {
84     return Convert.ToInt64(val.Value);
85     }
86     catch { return 0; }
87     }
88 william 220 public static UInt16 ToUInt16(this NumericBoxBase val)
89 william 88 {
90     try
91     {
92     return Convert.ToUInt16(val.Value);
93     }
94     catch { return 0; }
95     }
96 william 220 public static UInt32 ToUInt32(this NumericBoxBase val)
97 william 88 {
98     try
99     {
100     return Convert.ToUInt32(val.Value);
101     }
102     catch { return 0; }
103     }
104 william 220 public static UInt64 ToUInt64(this NumericBoxBase val)
105 william 88 {
106     try
107     {
108     return Convert.ToUInt64(val.Value);
109     }
110     catch { return 0; }
111     }
112 william 220 public static Single ToSingle(this NumericBoxBase val)
113 william 88 {
114     try
115     {
116     return Convert.ToSingle(val.Value);
117     }
118     catch { return 0; }
119     }
120 william 220 public static double ToDouble(this NumericBoxBase val)
121 william 88 {
122     try
123     {
124     return Convert.ToDouble(val.Value);
125     }
126     catch { return 0; }
127     }
128 william 220 public static decimal ToDecimal(this NumericBoxBase val)
129 william 88 {
130     try
131     {
132     return Convert.ToDecimal(val.Value);
133     }
134     catch { return 0; }
135     }
136 william 220 public static string ToString(this NumericBoxBase val)
137 william 88 {
138     try
139     {
140     return Convert.ToString(val.Value);
141     }
142     catch { return "0"; }
143     }
144     }
145     #endregion
146     }

  ViewVC Help
Powered by ViewVC 1.1.22