This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomCheckedComboBoxEdit.cs
100 lines (88 loc) · 3.82 KB
/
CustomCheckedComboBoxEdit.cs
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
using DevExpress.Utils;
using DevExpress.Utils.Drawing;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.ViewInfo;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace CustomEdit
{
public class CustomCheckedComboBoxEdit : CheckedComboBoxEdit
{
CheckedListBoxControl listBoxControl;
ImageCollection images;
static CustomCheckedComboBoxEdit()
{ RepositoryItemCustomCheckedComboBoxEdit.Register(); }
public CustomCheckedComboBoxEdit() {}
~CustomCheckedComboBoxEdit()
{
if (listBoxControl != null)
listBoxControl.DrawItem -= CustomCheckedComboBoxEdit_DrawItem;
images.Dispose();
}
public override string EditorTypeName
{
get {return RepositoryItemCustomCheckedComboBoxEdit.EditorName;}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemCustomCheckedComboBoxEdit Properties
{
get { return base.Properties as RepositoryItemCustomCheckedComboBoxEdit; }
}
protected override PopupContainerControl CreatePopupCheckListControl()
{
PopupContainerControl containerControl = base.CreatePopupCheckListControl();
SetControl(containerControl);
return containerControl;
}
private void SetControl(PopupContainerControl containerControl)
{
foreach (Control con in containerControl.Controls)
{
if (con.GetType().BaseType == typeof(CheckedListBoxControl))
{
listBoxControl = con as CheckedListBoxControl;
listBoxControl.DrawItem += CustomCheckedComboBoxEdit_DrawItem;
return;
}
}
}
void CustomCheckedComboBoxEdit_DrawItem(object sender, ListBoxDrawItemEventArgs e)
{
if (listBoxControl != null && Properties.CheckStyle != DevExpress.XtraEditors.Controls.CheckStyles.Standard)
{
CheckedListBoxControl lbControl = sender as CheckedListBoxControl;
CheckedListBoxViewInfo vi = lbControl.GetViewInfo() as CheckedListBoxViewInfo;
CheckedListBoxViewInfo.CheckedItemInfo checkItemInfo = vi.GetItemByIndex(e.Index) as CheckedListBoxViewInfo.CheckedItemInfo;
checkItemInfo.CheckArgs.CheckStyle = Properties.CheckStyle;
if (Properties.CheckStyle == DevExpress.XtraEditors.Controls.CheckStyles.Radio)
return;
SetProperties(checkItemInfo);
}
}
protected void SetProperties(CheckedListBoxViewInfo.CheckedItemInfo checkItemInfo)
{
CheckObjectInfoArgs e = checkItemInfo.CheckArgs;
if (e.DefaultImages == null)
e.DefaultImages = LoadImages();
int style = (int)e.CheckStyle;
style = style * 4;
if (style > e.DefaultImages.Count - 1) return;
e.PictureUnchecked = e.DefaultImages[style] as Bitmap;
e.PictureChecked = e.DefaultImages[style + 1] as Bitmap;
e.PictureGrayed = e.DefaultImages[style + 3] as Bitmap;
}
protected ArrayList LoadImages()
{
if (images == null)
{
images = DevExpress.Utils.Controls.ImageHelper.CreateImageCollectionFromResources("DevExpress.XtraEditors.Images.CheckBoxes.gif", typeof(RepositoryItemCheckEdit).Assembly, new Size(18, 18), Color.Magenta);
}
return new ArrayList(images.Images);
}
}
}