yangyin
2025-02-28 baa80d650adebcce70f1113cc1020c6039c159a0
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
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using DPumpHydr.WinFrmUI.WenSkin.Controls;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Design.Editor
{
    public class WenCollectionEditor : CollectionEditor
    {
        public WenCollectionEditor(Type type) : base(type)
        {
        }
        protected override CollectionForm CreateCollectionForm()
        {
            CollectionForm frm = base.CreateCollectionForm();
            if (frm.GetType().GetField("propertyBrowser", BindingFlags.NonPublic | BindingFlags.Instance) is FieldInfo propertyGridFielInfo)
            {
                (propertyGridFielInfo.GetValue(frm) as System.Windows.Forms.PropertyGrid).HelpVisible = true;
            }
 
            if (frm.GetType().GetField("listbox", BindingFlags.NonPublic | BindingFlags.Instance) is FieldInfo listboxFielInfo)
            {
                if (listboxFielInfo.GetValue(frm) is ListBox listBox)
                {
                    listBox.DrawMode = DrawMode.OwnerDrawFixed;
                    listBox.DrawItem += (s, e) =>
                    {
                        if (e.Index < 0)
                            return;
                        Graphics g = e.Graphics.SetGDIHigh();
                        Rectangle rec = e.Bounds;
 
                        int cut = (listBox.Items.Count.ToString().Length + 1) * 8;
                        Rectangle recStr = new Rectangle(cut, rec.Y + 1, rec.Width - cut, rec.Height - 2);
                        g.ResetClip();
                        g.FillRectangle(new SolidBrush(e.BackColor), recStr);
 
                        object value = listBox.Items[e.Index];
 
                        string text = value.GetType().GetProperty("Value").GetValue(value, null)?.ToString();
 
                        g.DrawString(text, e.Font, new SolidBrush(e.ForeColor), recStr);
                    };
                }
            }
            frm.Width = 600;
            frm.Height = 370;
            return frm;
        }
    }
}