yangyin
2024-10-22 90573e299e2eea301a0ad8585a7e6b95d7a798bb
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
#region Imports
 
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotWidgetPanel
 
    public class ParrotWidgetPanel : System.Windows.Forms.Panel
    {
        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
            if (!ControlsAsWidgets)
            {
                foreach (object obj in base.Controls)
                {
                    Control control = (Control)obj;
                    control.MouseDown += WidgetDown;
                    control.MouseUp += WidgetUp;
                    control.MouseMove += WidgetMove;
                }
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Reat controls as widgets")]
        public bool ControlsAsWidgets { get; set; }
 
        private void WidgetDown(object sender, MouseEventArgs e)
        {
            isDragging = true;
        }
 
        private void WidgetUp(object sender, MouseEventArgs e)
        {
            isDragging = false;
        }
 
        private void WidgetMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                ((Control)sender).Location = new Point(e.X, e.Y);
            }
        }
 
        private bool isDragging;
    }
 
    #endregion
}