Shuxia Ning
2025-02-13 2f1cbec203dcff25df7a5c2b51b13ec558f2c3db
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
 
using System;
using System.Drawing;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI
{
    public partial class VerifySliderPanel : Panel
    {
        public VerifySliderPanel()
        {
            InitializeComponent();
            //Initial();
        }
        public void Initial()
        {
            InitForm();
            InitContent();
            SizeChanged += (sender, e) =>
            {
                _sliderBackColor.Left = 0;
                _lblTip.Left = ClientSize.Width / 2 - _lblTip.Width / 2;
                _lblSuccessTip.Left = ClientSize.Width / 2 - _lblSuccessTip.Width / 2;
                _picSlider.Left = 0;
            };
        }
        public void SetStatusInfo(Color color, string info, bool isOk = false)
        {
            this.BackColor = color;
            _lblSuccessTip.Text = info;
            if (isOk)
            {
                _picSlider.SliderImage = IStation.WinFrmUI.Properties.Resources.right;
            }
            else
            {
                _picSlider.SliderImage = IStation.WinFrmUI.Properties.Resources.exclamationc32;
            }
        }
        #region method        
 
        /// <summary>
        /// 在picturebox的鼠标按下事件里,记录两个变量
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Pic_MouseDown(object sender, MouseEventArgs e)
        {
            _moveFlag = true;
        }
 
        /// <summary>
        /// 在picturebox的鼠标按下事件里
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Pic_MouseUp(object sender, MouseEventArgs e)
        {
            _moveFlag = false;
            if (!_successSlider)
            {
                _picSlider.Left = 0;
                _sliderBackColor.Width = 0;
            }
            else
            {
                _picSlider.SliderImage = Properties.Resources.right;
                _lblSuccessTip.ForeColor = Color.AliceBlue;// Color.FromArgb(102, 255, 178);
                _lblSuccessTip.Text = "验证成功";
                SliderSuccessEvent(true);
            }
        }
 
        //在picturebox鼠标移动
        private void Pic_MouseMove(object sender, MouseEventArgs e)
        {
            if (_moveFlag)
            {
                _picSlider.Top = 0;
                if (_picSlider.Left >= 0 && _picSlider.Left <= ClientSize.Width - _picSlider.Width - 1)
                {
                    _picSlider.Left += Convert.ToInt16(e.X);
                    _sliderBackColor.Width = _picSlider.Left;
                    _sliderBackColor.BringToFront();
                    _picSlider.BringToFront();
                    return;
                }
                if (_picSlider.Left < 0)
                {
                    _picSlider.Left = 0;
                    return;
                }
                if (_picSlider.Left > ClientSize.Width - _picSlider.Width)
                {
                    _picSlider.Left = ClientSize.Width - _picSlider.Width;
                }
                _sliderBackColor.Visible = false;
                this.ForeColor = Color.White;
                this.BackColor = Color.FromArgb(0, 139, 0);//拖到底, 成功后的颜色
                _successSlider = true;
                _picSlider.SetBorderColor(Color.FromArgb(0, 139, 0));
            }
        }
        #endregion
 
        #region property
        private Label _lblTip;
        private Label _lblSuccessTip;
        private ImageSliderPanel _picSlider;
        private Panel _sliderBackColor;
        bool _successSlider = false;//是否滑动到最右侧
        bool _moveFlag;//是否已经按下.
        private string _sliderTipInfo = "请拖动左侧滑块";
        public string SliderTipInfo
        {
            get { return _sliderTipInfo; }
            set { _sliderTipInfo = value; }
        }
        #endregion
 
        #region 窗口初始化
        private void InitForm()
        {
            DoubleBuffered = true;
            Height = 40;
            Width = 290;
            Font = new Font("微软雅黑", 12, GraphicsUnit.Pixel);
            BackColor = Color.FromArgb(100, 149, 237);//开始时的背景色,还未拖动时  
        }
 
        private void InitContent()
        {
            _sliderBackColor = new Panel
            {
                Parent = this,
                Width = 1,
                Height = 40,
                ForeColor = Color.White,
 
                BackColor = Color.FromArgb(0, 191, 255)//拖动后, 左侧的背景色
            };
 
            _lblTip = new Label
            {
                Parent = _sliderBackColor,
                Text = _sliderTipInfo,
                AutoSize = true,
                ForeColor = Color.Black
            };
            _lblTip.Top = ClientSize.Height / 2 - _lblTip.Height / 2;
 
            _lblSuccessTip = new Label
            {
                Parent = this,
                Text = _sliderTipInfo,
                AutoSize = true,
                ForeColor = Color.White
            };
            _lblSuccessTip.Top = ClientSize.Height / 2 - _lblSuccessTip.Height / 2;
 
            _picSlider = new ImageSliderPanel
            {
                Parent = this,
                Cursor = Cursors.Hand,
                SliderImage = IStation.WinFrmUI.Properties.Resources.arrow,
                Size = new Size(40, 40),
                BorderStyle = BorderStyle.FixedSingle,
                ForeColor = Color.White,
                BackColor = Color.FromArgb(255, 255, 255),//小滑块的颜色
                Top = 0
            };
            _picSlider.BringToFront();
            _picSlider.MouseUpEvent += Pic_MouseUp;
            _picSlider.MouseDownEvent += Pic_MouseDown;
            _picSlider.MouseMoveEvent += Pic_MouseMove;
        }
        #endregion
 
        #region event
        public delegate void SliderSuccessEventHandler(bool sliderSuccess);
        public event SliderSuccessEventHandler SliderSuccessEvent;
        #endregion
    }
}