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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region RoyalMenuStrip
 
    public class RoyalMenuStrip : MenuStrip
    {
        private Color hotTrackColor;
        public Color HotTrackColor
        {
            get => hotTrackColor;
            set { hotTrackColor = value; Invalidate(); }
        }
 
        private Color selectedColor;
        public Color SelectedColor
        {
            get => selectedColor;
            set { selectedColor = value; Invalidate(); }
        }
 
        public RoyalMenuStrip()
        {
            Renderer = new RoyalToolStripRenderer();
            Dock = DockStyle.None;
            AutoSize = false;
            Padding = new Padding(1);
            Size = new(100, 30);
        }
 
        protected override void OnItemAdded(ToolStripItemEventArgs e)
        {
            int width = 1;
 
            for (int i = 0; i < Items.Count; i++)
            {
                width += Items[i].Width;
            }
 
            width += 1;
 
            Size = new(width, 30);
 
            base.OnItemAdded(e);
        }
 
        protected override void OnItemRemoved(ToolStripItemEventArgs e)
        {
            int width = 1;
 
            for (int i = 0; i < Items.Count; i++)
            {
                width += Items[i].Width;
            }
 
            width += 1;
 
            Size = new(width, 30);
 
            base.OnItemRemoved(e);
        }
    }
 
    #endregion
}