forked from 0000duck/VisionEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCNumericUpDown.cs
More file actions
193 lines (182 loc) · 5.51 KB
/
CNumericUpDown.cs
File metadata and controls
193 lines (182 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using Controls.Properties;
namespace Controls
{
public delegate void DValueChanged(double value);
public partial class CNumericUpDown : UserControl
{
public CNumericUpDown()
{
InitializeComponent();
nud_value.Text = Value.ToString();
}
/// <summary>
/// 值改变事件
/// </summary>
public event DValueChanged ValueChanged;
/// <summary>
/// 点击一下值的变化量
/// </summary>
private decimal _incremeent = 1;
public decimal Incremeent
{
get { return _incremeent; }
set { _incremeent = value; }
}
/// <summary>
/// 小数位数
/// </summary>
private int _decimalPlaces = 0;
public int DecimalPlaces
{
get { return _decimalPlaces; }
set
{
_decimalPlaces = value;
nud_value.DecimalPlaces = value;
}
}
/// <summary>
/// 最小值
/// </summary>
private decimal _minValue = 0;
public decimal MinValue
{
get { return _minValue; }
set
{
_minValue = value;
nud_value.Minimum = value;
}
}
/// <summary>
/// 最大值
/// </summary>
private decimal _maxValue = 100;
public decimal MaxValue
{
get { return _maxValue; }
set
{
_maxValue = value;
nud_value.Maximum = value;
}
}
/// <summary>
/// 值
/// </summary>
private double _value = 0;
public double Value
{
get
{
return _value;
}
set
{
_value = value;
nud_value.Text = value.ToString();
}
}
private void btn_add_MouseEnter(object sender, EventArgs e)
{
try
{
btn_add.BringToFront();
if (nud_value.Value < MaxValue)
{
btn_add.FlatAppearance.MouseDownBackColor = Color.Gray;
btn_add.FlatAppearance.MouseOverBackColor = Color.DarkGray;
btn_add.Image = Resources.blueAdd;
}
else
{
btn_add.FlatAppearance.MouseDownBackColor = Color.White;
btn_add.FlatAppearance.MouseOverBackColor = Color.White;
}
}
catch { }
}
private void btn_add_MouseLeave(object sender, EventArgs e)
{
btn_add.Image = Resources.grayAdd;
}
private void btn_sub_MouseEnter(object sender, EventArgs e)
{
try
{
btn_sub.BringToFront();
if (nud_value.Value >= MinValue)
{
btn_sub.FlatAppearance.MouseDownBackColor = Color.Gray;
btn_sub.FlatAppearance.MouseOverBackColor = Color.DarkGray;
btn_sub.Image = Resources.blueSub;
}
else
{
btn_sub.FlatAppearance.MouseDownBackColor = Color.White;
btn_sub.FlatAppearance.MouseOverBackColor = Color.White;
}
}
catch { }
}
private void btn_add_Click(object sender, EventArgs e)
{
try
{
if (nud_value.Value + Incremeent <= MaxValue)
nud_value.Text = (nud_value.Value + Incremeent).ToString();
if (nud_value.Value >= MaxValue)
{
btn_add.FlatAppearance.MouseDownBackColor = Color.White;
btn_add.FlatAppearance.MouseOverBackColor = Color.White;
btn_add.Image = Resources.grayAdd;
}
}
catch { }
}
private void btn_sub_Click(object sender, EventArgs e)
{
try
{
if (nud_value.Value + Incremeent > MinValue)
nud_value.Text = (nud_value.Value - Incremeent).ToString();
if (nud_value.Value <= MinValue)
{
btn_sub.FlatAppearance.MouseDownBackColor = Color.White;
btn_sub.FlatAppearance.MouseOverBackColor = Color.White;
btn_sub.Image = Resources.graySub;
}
}
catch { }
}
private void nud_value_ValueChanged(object sender, EventArgs e)
{
Value = (double)nud_value.Value;
if (ValueChanged != null)
ValueChanged(Value);
}
private void UserControl1_Leave(object sender, EventArgs e)
{
lbl_line.Height = 1;
lbl_line.BackColor = Color.Gray;
}
private void UserControl1_Enter(object sender, EventArgs e)
{
lbl_line.Height = 2;
lbl_line.BackColor = Color.FromArgb(18, 150, 219);
}
private void btn_sub_MouseLeave(object sender, EventArgs e)
{
btn_sub.Image = Resources.graySub;
}
}
}