yangyin
2025-02-24 b3b65a002fe68b1383314098790f5a153b87765f
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 DPumpHydr.WinFrmUI.RLT.Manager;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using static DPumpHydr.WinFrmUI.RLT.Helper.MaterialDrawHelper;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region MaterialCheckListBox
 
    public class MaterialCheckListBox : System.Windows.Forms.Panel, MaterialControlI
    {
        [Browsable(false)]
        public int Depth { get; set; }
 
        [Browsable(false)]
        public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
 
        [Browsable(false)]
        public MaterialMouseState MouseState { get; set; }
 
        public bool Striped { get; set; }
 
        public Color StripeDarkColor { get; set; }
 
        public ItemsList Items { get; set; }
 
        public MaterialCheckListBox() : base()
        {
            this.DoubleBuffered = true;
            this.Items = new ItemsList(this);
            this.AutoScroll = true;
        }
 
        //protected override void OnPaint(PaintEventArgs e)
        //{
        //    base.OnPaint(e);
        //    MessageBox.Show("Start!");
 
        //    foreach (Control CTRL in FindForm().Controls)
        //    {
        //        try
        //        {
        //            if (CTRL is MaterialCheckListBox)
        //            {
        //                MessageBox.Show("OK - " + CTRL.Name);
        //                MaterialCheckListBox MCLB = CTRL as MaterialCheckListBox;
        //                MessageBox.Show("YES - " + MCLB.Name + " - " + MCLB.Items.Count);
        //                foreach (var Item in MCLB.Items)
        //                {
        //                    if (!MCLB.Controls.Contains(Item))
        //                    {
        //                        MessageBox.Show("I - " + Item.Text);
        //                        Items.Add(Item.Text, Item.Checked);
        //                    }
        //                }
        //            }
        //        }
        //        catch
        //        {
        //            //
        //        }
        //    }
        //}
 
        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            if (DesignMode)
            {
                BackColorChanged += (sender, args) => BackColor = Parent.BackColor;
                BackColor = Parent.BackColor == Color.Transparent ? ((Parent.Parent == null || (Parent.Parent != null && Parent.Parent.BackColor == Color.Transparent)) ? SkinManager.BackgroundColor : Parent.Parent.BackColor) : Parent.BackColor;
            }
            else
            {
                BackColorChanged += (sender, args) => BackColor = BlendColor(Parent.BackColor, SkinManager.BackgroundAlternativeColor, SkinManager.BackgroundAlternativeColor.A);
                BackColor = BlendColor(Parent.BackColor == Color.Transparent ? ((Parent.Parent == null || (Parent.Parent != null && Parent.Parent.BackColor == Color.Transparent)) ? SkinManager.BackgroundColor : Parent.Parent.BackColor) : Parent.BackColor, SkinManager.BackgroundAlternativeColor, SkinManager.BackgroundAlternativeColor.A);
            }
        }
 
        public CheckState GetItemCheckState(int Index)
        {
            return Items[Index].CheckState;
        }
 
        public class ItemsList : List<MaterialCheckBox>
        {
            private System.Windows.Forms.Panel _parent;
 
            public ItemsList(System.Windows.Forms.Panel parent)
            {
                _parent = parent;
            }
 
            public delegate void SelectedIndexChangedEventHandler(int Index);
 
            public void Add(string text)
            {
                Add(text, false);
            }
 
            public void Add(string text, bool defaultValue)
            {
                MaterialCheckBox cb = new();
                Add(cb);
                cb.Checked = defaultValue;
                cb.Text = text;
            }
 
            public new void Add(MaterialCheckBox value)
            {
                base.Add(value);
                _parent.Controls.Add(value);
                value.Dock = DockStyle.Top;
            }
 
            public new void Remove(MaterialCheckBox value)
            {
                base.Remove(value);
                _parent.Controls.Remove(value);
            }
        }
    }
 
    #endregion
}