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
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
#region Imports
 
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotFormDropShadow
 
    public class ParrotFormDropShadow : Component
    {
        public ParrotFormDropShadow()
        {
            RefreshUI.Interval = 250;
            RefreshUI.Tick += RefreshUI_Tick;
            RefreshUI.Enabled = true;
        }
 
        public override ISite Site
        {
            get => base.Site;
            set
            {
                base.Site = value;
 
                if (value == null)
                {
                    return;
                }
 
                if (value.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost)
                {
                    IComponent rootComponent = designerHost.RootComponent;
                    if (rootComponent is ContainerControl)
                    {
                        EffectedForm = rootComponent as Form;
                    }
                }
            }
        }
 
        private void RefreshUI_Tick(object sender, EventArgs e)
        {
            try
            {
                Mainform_Shown(null, null);
                EffectedForm.Shown += Mainform_Shown;
                EffectedForm.Resize += Mainform_Resize;
                EffectedForm.LocationChanged += Mainform_Resize;
                RefreshUI.Enabled = false;
                RefreshUI.Dispose();
            }
            catch
            {
            }
        }
 
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            ds.Dispose();
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Change the shadow angle, sorry this option is trial and error")]
        public int ShadowAngle { get; set; } = 2;
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The effected form(will remove ellipse from effected control)")]
        public Form EffectedForm { get; set; }
 
        private void Mainform_Shown(object sender, EventArgs e)
        {
            Rectangle bounds = EffectedForm.Bounds;
            ds.Bounds = bounds;
            ds.Location = new Point(EffectedForm.Location.X + ShadowAngle, EffectedForm.Location.Y + ShadowAngle);
            ds.Show();
            EffectedForm.BringToFront();
        }
 
        private void Mainform_Resize(object sender, EventArgs e)
        {
            ds.Visible = EffectedForm.WindowState == FormWindowState.Normal;
            if (ds.Visible)
            {
                Rectangle bounds = EffectedForm.Bounds;
                ds.Bounds = bounds;
                ds.Location = new Point(EffectedForm.Location.X + ShadowAngle, EffectedForm.Location.Y + ShadowAngle);
            }
            EffectedForm.BringToFront();
        }
 
        private readonly Timer RefreshUI = new();
        private readonly DropShadow ds = new();
 
        public class DropShadow : Form
        {
            public DropShadow()
            {
                BackColor = Color.Black;
                base.Opacity = 0.3;
                base.ShowInTaskbar = false;
                base.FormBorderStyle = FormBorderStyle.None;
                base.StartPosition = FormStartPosition.Manual;
            }
 
            protected override CreateParams CreateParams
            {
                get
                {
                    CreateParams createParams = base.CreateParams;
                    createParams.ExStyle = createParams.ExStyle | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE;
                    return createParams;
                }
            }
 
            private const int WS_EX_TRANSPARENT = 32;
 
            private const int WS_EX_NOACTIVATE = 134217728;
        }
    }
 
    #endregion
}