tangxu
2024-12-16 23fadc9cb0c09b665a1bbcef7eaf16f916045dc4
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#region Imports
 
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotSlidingPanel
 
    public class ParrotSlidingPanel : ParrotGradientPanel
    {
        public ParrotSlidingPanel()
        {
            Dock = DockStyle.Left;
            CollapseChanged();
            base.BottomRight = Color.DodgerBlue;
            base.TopLeft = Color.Black;
            base.TopRight = Color.Black;
            base.BottomLeft = Color.Black;
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Is the panel collapsed")]
        public bool Collapsed
        {
            get => collapsed;
            set
            {
                collapsed = value;
                CollapseChanged();
                CollapsedStateChanged();
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The panel width expanded")]
        public int PanelWidthExpanded
        {
            get => panelWidthExpanded;
            set
            {
                panelWidthExpanded = value;
                if (!Collapsed)
                {
                    base.Size = new Size(panelWidthExpanded, base.Height);
                }
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The panel width expanded")]
        public int PanelWidthCollapsed
        {
            get => panelWidthCollapsed;
            set
            {
                panelWidthCollapsed = value;
                if (Collapsed)
                {
                    base.Size = new Size(panelWidthCollapsed, base.Height);
                }
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Hide controls when collapsed")]
        public bool HideControls { get; set; }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The control used to collapse/expand the sliding panel")]
        public Control CollapseControl
        {
            get => collapseControl;
            set
            {
                collapseControl = value;
                if (collapseControl != null)
                {
                    collapseControl.Click += SwitchCollapsed;
                }
            }
        }
 
        private void SwitchCollapsed(object sender, EventArgs e)
        {
            if (Collapsed)
            {
                Collapsed = false;
                return;
            }
            Collapsed = true;
        }
 
        private void CollapseChanged()
        {
            if (!collapsed)
            {
                while (base.Width < panelWidthExpanded)
                {
                    if (base.Width < panelWidthExpanded / 10 * 6)
                    {
                        base.Size = new Size(base.Width + 30, base.Height);
                        sleeper.Sleep(40);
                    }
                    else if (base.Width < panelWidthExpanded / 10 * 4)
                    {
                        base.Size = new Size(base.Width + 20, base.Height);
                        sleeper.Sleep(40);
                    }
                    else
                    {
                        base.Size = new Size(base.Width + 10, base.Height);
                        sleeper.Sleep(40);
                    }
                }
                base.Size = new Size(panelWidthExpanded, base.Height);
                if (HideControls)
                {
                    foreach (object obj in base.Controls)
                    {
                        Control control = (Control)obj;
                        if (control != collapseControl)
                        {
                            control.Visible = true;
                        }
                    }
                }
                return;
            }
            if (!HideControls)
            {
                goto IL_FB;
            }
            IEnumerator enumerator = base.Controls.GetEnumerator();
            while (enumerator.MoveNext())
            {
                object obj2 = enumerator.Current;
                Control control2 = (Control)obj2;
                if (control2 != collapseControl)
                {
                    control2.Visible = false;
                }
            }
            goto IL_FB;
        IL_5E:
            if (base.Width > panelWidthExpanded / 5 * 3)
            {
                base.Size = new Size(base.Width - 30, base.Height);
                sleeper.Sleep(40);
            }
            else if (base.Width > panelWidthExpanded / 5 * 2)
            {
                base.Size = new Size(base.Width - 20, base.Height);
                sleeper.Sleep(40);
            }
            else
            {
                base.Size = new Size(base.Width - 10, base.Height);
                sleeper.Sleep(40);
            }
        IL_FB:
            if (base.Width <= panelWidthCollapsed)
            {
                base.Size = new Size(panelWidthCollapsed, base.Height);
                return;
            }
            goto IL_5E;
        }
 
        protected override void OnDockChanged(EventArgs e)
        {
            base.OnDockChanged(e);
            if (Dock != DockStyle.Left & Dock != DockStyle.Right)
            {
                Dock = DockStyle.Left;
            }
        }
 
        public event EventHandler OnCollapsedStateChanged;
 
        protected virtual void CollapsedStateChanged()
        {
            OnCollapsedStateChanged?.Invoke(this, new EventArgs());
        }
 
        private readonly ParrotSleeper sleeper = new();
 
        private bool collapsed = true;
 
        private int panelWidthExpanded = 200;
 
        private int panelWidthCollapsed = 50;
        private Control collapseControl;
    }
 
    #endregion
}