This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/
CustomEdit.cs
177 lines (147 loc) · 6.01 KB
/
CustomEdit.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraEditors.Repository;
using System.Drawing;
using System.Reflection;
using DevExpress.XtraEditors.Registrator;
using DevExpress.XtraEditors;
using System.ComponentModel;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Popup;
using DevExpress.Utils;
using DevExpress.Utils.Drawing.Helpers;
namespace WindowsApplication3 {
//The attribute that points to the registration method
[UserRepositoryItem("RegisterCustomEdit")]
public class RepositoryItemCustomEdit: RepositoryItemDateEdit {
//The static constructor which calls the registration method
static RepositoryItemCustomEdit() { RegisterCustomEdit(); }
//The unique name for the custom editor
public const string CustomEditName = "CustomEdit";
//Return the unique name
public override string EditorTypeName { get { return CustomEditName; } }
//Register the editor
public static void RegisterCustomEdit() {
//Icon representing the editor within a container editor's Designer
Image img = null;
try {
img = (Bitmap)Bitmap.FromStream(Assembly.GetExecutingAssembly().
GetManifestResourceStream("DevExpress.CustomEditors.CustomEdit.bmp"));
}
catch {
}
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(CustomEditName,
typeof(CustomEdit), typeof(RepositoryItemCustomEdit),
typeof(DateEditViewInfo), new ButtonEditPainter(), true, img));
}
//Override the Assign method
public override void Assign(RepositoryItem item) {
BeginUpdate();
try {
base.Assign(item);
RepositoryItemCustomEdit source = item as RepositoryItemCustomEdit;
if(source == null) return;
}
finally {
EndUpdate();
}
}
}
public class CustomEdit: DateEdit {
//The static constructor which calls the registration method
static CustomEdit() { RepositoryItemCustomEdit.RegisterCustomEdit(); }
//Initialize the new instance
public CustomEdit() {
//...
}
//Return the unique name
public override string EditorTypeName {
get {
return
RepositoryItemCustomEdit.CustomEditName;
}
}
//Override the Properties property
//Simply type-cast the object to the custom repository item type
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public new RepositoryItemCustomEdit Properties {
get { return base.Properties as RepositoryItemCustomEdit; }
}
protected internal virtual bool IsVistaDisplayMode() {
if(Properties.VistaDisplayMode == DefaultBoolean.False) return false;
if(Properties.VistaDisplayMode == DefaultBoolean.True) return true;
return NativeVista.IsVista;
}
protected override DevExpress.XtraEditors.Popup.PopupBaseForm CreatePopupForm() {
if(IsVistaDisplayMode()) return new CustomVistaPopupDateEditForm(this);
return new CustomPopupDateEditForm(this);
}
}
public class CustomVistaPopupDateEditForm: VistaPopupDateEditForm {
public CustomVistaPopupDateEditForm(DateEdit de) : base(de) { }
protected override CalendarControl CreateCalendar() {
return new CustomVistaDateEditCalendar();
}
}
public class CustomVistaDateEditCalendar: VistaCalendarControl {
public CustomVistaDateEditCalendar()
{
this.AutoSize = false;
btn = new SimpleButton();
btn.Click += OnNewButtonClick;
btn.Text = "New Button";
Controls.Add(btn);
btn.Size = new Size(100, 30);
btn.Location = new Point(Bounds.X + Bounds.Width / 2 - btn.Size.Width / 2, Bounds.Bottom - indent);
}
SimpleButton btn;
int indent = 5;
public SimpleButton Button { get {return btn; } }
void OnNewButtonClick(object sender, EventArgs e) {
XtraMessageBox.Show("New Button Click");
}
public override Size CalcBestSize() {
if(Button == null)
return base.CalcBestSize();
Size bestSize = base.CalcBestSize();
bestSize.Height += Button.Height + indent;
return bestSize;
}
}
public class CustomPopupDateEditForm: PopupDateEditForm {
public CustomPopupDateEditForm(DateEdit de) : base(de) { }
protected override CalendarControl CreateCalendar() {
return new CustomDateEditCalendar();
}
}
public class CustomDateEditCalendar: CalendarControl {
SimpleButton btn;
int indent = 5;
public CustomDateEditCalendar()
{
this.AutoSize = false;
btn = new SimpleButton();
btn.Click += OnNewButtonClick;
btn.Text = "New Button";
Controls.Add(btn);
btn.Size = new Size(100, 30);
btn.Location = new Point(Bounds.X + Bounds.Width / 2 - btn.Size.Width / 2, Bounds.Bottom - indent);
}
public SimpleButton Button { get { return btn; } }
void OnNewButtonClick(object sender, EventArgs e) {
XtraMessageBox.Show("New Button Click");
}
public override Size CalcBestSize()
{
if (Button == null)
return base.CalcBestSize();
Size bestSize = base.CalcBestSize();
bestSize.Height += Button.Height + indent;
Size = bestSize;
return bestSize;
}
}
}