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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.ComboBox;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Controls
{
    public class WenLableComboBox : WenControl
    {
        public WenLableComboBox()
        {
            wenComboBox = new WenComboBox();
            wenComboBox.SelectedIndexChanged += (s, e) =>
            {
                base.Text = wenComboBox.Text;
            };
            wenComboBox.TextChanged += (s, e) =>
            {
                base.Text = wenComboBox.Text;
            };
            wenComboBox.SizeChanged += (s, e) =>
            {
                this.Height = wenComboBox.Height;
            };
 
            this.Controls.Add(wenComboBox);
        }
 
        #region 私有属性
 
        private WenComboBox wenComboBox;
 
        private string textLable;
        #endregion
 
        #region 公有属性
 
 
 
        public override string Text { get => base.Text; set { base.Text = value; wenComboBox.Text = value; } }
 
        [Category("Wen"), Description("下拉选项组合功能")]
        [DefaultValue(typeof(ComboBoxStyle), "DropDown")]
        public ComboBoxStyle DropDownStyle { get => wenComboBox.DropDownStyle; set => wenComboBox.DropDownStyle = value; }
 
        [Category("Wen"), Description("标签显示文本内容")]
        public string TextLable
        {
            get => textLable;
            set
            {
                textLable = value;
                this.Invalidate();
                SetLocationSize();
            }
        }
 
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor", typeof(UITypeEditor))]
        [Localizable(true)]
        [MergableProperty(false)]
        public ObjectCollection Items => wenComboBox.Items;
        #endregion
 
        private void SetLocationSize()
        {
            int w = TextRenderer.MeasureText(TextLable, this.Font).Width + 3;
            int h = (this.Height - wenComboBox.Height) / 2;
            wenComboBox.Location = new Point(w, h < 0 ? 0 : h);
            wenComboBox.Size = new Size(this.Width - w, (this.Height - wenComboBox.Height) / 2);
        }
 
        #region 重写事件
 
        //保持控件宽度
        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            base.SetBoundsCore(x, y, width, wenComboBox.Height, specified);
            SetLocationSize();
        }
 
        #endregion
 
        #region 重绘
 
        protected override void WenOnPaint(Graphics g, Rectangle rec, PaintEventArgs e)
        {
            base.WenOnPaint(g, rec, e);
            this.DrawString(this.TextLable, g, rec);
        }
 
        #endregion
 
        public new void Focus()
        {
            wenComboBox.Focus();
        }
    }
}