c# Winform PropertyGrid 实现下拉框 多选
2021-06-05 11:03
标签:control ima nts partial 打开 drop tor alt join 源码分享 链接:https://pan.baidu.com/s/1e8D-WoTYmA-D7vm88TTQrA c# Winform PropertyGrid 实现下拉框 多选 标签:control ima nts partial 打开 drop tor alt join 原文地址:https://www.cnblogs.com/aaaaq/p/10802083.html 1 using PropertyGridHelpers.Controls;
2 using System;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Drawing.Design;
6 using System.Windows.Forms;
7 using System.Windows.Forms.Design;
8
9 namespace PropertyGridHelpers.UIEditors
10 {
11
12 public class FlagEnumUIEditor : UITypeEditor
13 {
14 private CheckedListBoxEx check;
15
16 public FlagEnumUIEditor()
17 {
18 check = new CheckedListBoxEx();
19 check.BorderStyle = BorderStyle.None;
20 }
21
22 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
23 {
24 if (context != null && context.Instance != null && provider != null)
25 {
26 IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
27 if (service != null)
28 {
29 List
1 using System;
2 using System.ComponentModel;
3 using System.Windows.Forms;
4 using System.Collections.Generic;
5 using System.Linq;
6
7 namespace PropertyGridHelpers.Controls
8 {
9
10 public class CheckedListBoxEx : CheckedListBox
11 {
12 private Container components = null;
13 public CheckedListBoxEx()
14 {
15 InitializeComponent();
16 }
17 protected override void Dispose(bool disposing)
18 {
19 if (disposing)
20 {
21 if (components != null)
22 components.Dispose();
23 }
24 base.Dispose(disposing);
25 }
26
27 #region Component Designer generated code
28
29 private void InitializeComponent()
30 {
31 this.CheckOnClick = true;
32 }
33 protected override void OnItemCheck(ItemCheckEventArgs e)
34 {
35 base.OnItemCheck(e);
36 }
37 #endregion
38
39 #region Add
40 public CheckItem Add(string code, string value)
41 {
42 CheckItem item = new CheckItem(code, value);
43 Items.Add(item);
44 return item;
45 }
46 public CheckItem Add(CheckItem item)
47 {
48 Items.Add(item);
49 return item;
50 }
51 #endregion
52 #region 获取选择值
53 public string GetSelectItemValueText { get { return string.Join(",", GetSelectItemAll.Select(n => n.Value)); } }
54 public string GetSelectItemKeyText { get { return string.Join(",", GetSelectItemAll.Select(n => n.Key)); } }
55 public List
1 namespace PropertyGridHelpers.Controls
2 {
3 ///
1 using PropertyGridHelpers.UIEditors;
2 using System.ComponentModel;
3 using System.Windows.Forms;
4
5 namespace WindowsFormsApplication1
6 {
7 public partial class Form1 : Form
8 {
9 public Form1()
10 {
11 InitializeComponent();
12 propertyGrid1.SelectedObject = new PropertyList(); ;
13 }
14 }
15 class PropertyList
16 {
17 string m_dir;
18 [EditorAttribute(typeof(FlagEnumUIEditor), typeof(System.Drawing.Design.UITypeEditor))]
19 [DisplayName("Direction")]
20 [Description("Direction property")]
21 public string Dir
22 {
23 get
24 {
25 return m_dir;
26 }
27 set
28 {
29 m_dir = value;
30 }
31 }
32 }
33
34 }
提取码:bdrd
复制这段内容后打开百度网盘手机App,操作更方便哦
文章标题:c# Winform PropertyGrid 实现下拉框 多选
文章链接:http://soscw.com/index.php/essay/90838.html