-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckedImageComboBoxEdit.cs
99 lines (79 loc) · 3.86 KB
/
CheckedImageComboBoxEdit.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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.XtraEditors.Registrator;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.Utils;
using DevExpress.Utils.Drawing;
using System.Drawing;
using System.ComponentModel;
namespace DXSample {
public class CheckedImageComboBoxEdit : CheckedComboBoxEdit {
static CheckedImageComboBoxEdit() { RepositoryItemCheckedImageComboBoxEdit.RegisterCheckedImageComboBoxEdit(); }
public CheckedImageComboBoxEdit() { }
CheckedListBoxControl listBox = null;
public override string EditorTypeName { get { return
RepositoryItemCheckedImageComboBoxEdit.CustomEditName; } }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemCheckedImageComboBoxEdit Properties {
get { return base.Properties as RepositoryItemCheckedImageComboBoxEdit; }
}
protected override PopupContainerControl CreatePopupCheckListControl() {
PopupContainerControl ctrl = base.CreatePopupCheckListControl();
CheckedListBoxControl listBox = GetCheckedListBoxControl(ctrl);
if(Properties.CanShowImageInDropDown)
listBox.DrawItem += OnDrawItem;
return ctrl;
}
private CheckedListBoxControl GetCheckedListBoxControl(PopupContainerControl ctrl) {
foreach(Control c in ctrl.Controls)
if(c is CheckedListBoxControl)
return c as CheckedListBoxControl;
return null;
}
void OnDrawItem(object sender, ListBoxDrawItemEventArgs e) {
if(e.Index == 0) return;
listBox = sender as CheckedListBoxControl;
CheckedListBoxViewInfo viewInfo = listBox.GetViewInfo() as CheckedListBoxViewInfo;
Image image = Properties.GetItemImage(e.Index - 1);
if(image == null) return;
DrawCheckedItem(e, viewInfo, image);
e.Handled = true;
}
private void DrawCheckedItem(ListBoxDrawItemEventArgs e, CheckedListBoxViewInfo viewInfo, Image image) {
CheckedListBoxViewInfo.CheckedItemInfo itInfo = viewInfo.GetItemByIndex(e.Index);
FillRectangle(e.Appearance, e.Cache, e.Bounds);
DrawCheckBox(itInfo.CheckArgs, e.Graphics, viewInfo);
DrawImage(itInfo.CheckArgs.GlyphRect, e.Graphics, image);
DrawString(itInfo, e.Appearance, e.Cache);
}
private void FillRectangle(AppearanceObject appearance, GraphicsCache cache, Rectangle rect) {
appearance.FillRectangle(cache, rect);
}
private void DrawCheckBox(CheckObjectInfoArgs checkArgs, Graphics gr, CheckedListBoxViewInfo viewInfo) {
checkArgs.Graphics = gr;
viewInfo.CheckMarkPainter.DrawObject(checkArgs);
}
private void DrawImage(Rectangle rect, Graphics gr, Image image) {
Point point = new Point(rect.Right + 2, rect.Y);
gr.DrawImage(image, point);
}
private void DrawString(CheckedListBoxViewInfo.CheckedItemInfo itInfo,
AppearanceObject appearance, GraphicsCache cache) {
Rectangle textRect = new Rectangle(itInfo.TextRect.X + RepositoryItemCheckedImageComboBoxEdit.ImageWidth + 2,
itInfo.TextRect.Y, itInfo.TextRect.Width - RepositoryItemCheckedImageComboBoxEdit.ImageWidth - 2,
itInfo.TextRect.Height);
appearance.DrawString(cache, itInfo.Text, textRect);
}
protected override void Dispose(bool disposing) {
if(disposing) {
if(listBox != null)
listBox.DrawItem -= OnDrawItem;
}
base.Dispose(disposing);
}
}
}