-
Notifications
You must be signed in to change notification settings - Fork 1
/
ColorEditor.cs
91 lines (79 loc) · 2.46 KB
/
ColorEditor.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
/*
* Creato da SharpDevelop.
* Utente: Family Rose
* Data: 01/02/2009
* Ora: 21.01
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
namespace mkdb
{
public class wxColor : wx.Colour
{
public wxColor()
{
}
public wxColor(byte red, byte green, byte blue)
{
Set(red, green, blue);
}
public override string ToString()
{
return this.Red + "; " + this.Green + "; " + this.Blue;
}
}
public class wxColorEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
// We will use a window for property editing.
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (context == null || context.Instance == null || provider == null)
return value;
wxColor color = (wxColor)value;
System.Windows.Forms.ColorDialog colDialog = new System.Windows.Forms.ColorDialog();
colDialog.Color = new System.Drawing.Color();
colDialog.Color = System.Drawing.Color.FromArgb(255, color.Red, color.Green, color.Blue);
if (colDialog.ShowDialog() != DialogResult.Cancel)
{
wxColor retcolor = new wxColor(colDialog.Color.R,
colDialog.Color.G,
colDialog.Color.B);
return retcolor;
}
return value;
}
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
if (e.Value != null)
{
if (e.Value is wxColor)
{
System.Drawing.Color col = new System.Drawing.Color();
col = System.Drawing.Color.FromArgb(255, ((wxColor)e.Value).Red,
((wxColor)e.Value).Green,
((wxColor)e.Value).Blue);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(col);
e.Graphics.FillRectangle(brush, e.Bounds);
}
}
base.PaintValue(e);
}
}
}