|
Posted on 2006-06-18 10:57 东人EP 阅读(343) 评论(1) 编辑 收藏 引用 所属分类: .NET
1
using
System;
2
using
System.Collections.Generic;
3
using
System.ComponentModel;
4
using
System.Data;
5
using
System.Drawing;
6
using
System.Text;
7
using
System.Windows.Forms;
8
9
namespace
MSOfficeColorPicker
10
{
11
public
partial
class
MSOfficeColorPicker : Form
12
{
13
public
MSOfficeColorPicker(
int
x,
int
y)
14
{
15
Size
=
new
Size(
158
,
132
);
16
FormBorderStyle
=
FormBorderStyle.FixedDialog;
17
MinimizeBox
=
MaximizeBox
=
ControlBox
=
false
;
18
ShowInTaskbar
=
false
;
19
CenterToScreen();
20
Location
=
new
Point(x, y);
21
BuildPalette();
22
moreColorsButton.Text
=
"
More colors
"
;
23
moreColorsButton.Size
=
new
Size(
142
,
22
);
24
moreColorsButton.Location
=
new
Point(
5
,
99
);
25
moreColorsButton.Click
+=
new
EventHandler(moreColorsButton_Click);
26
moreColorsButton.FlatStyle
=
FlatStyle.Popup;
27
Controls.Add(moreColorsButton);
28
//
"invisible" button to cancel at Escape
29
cancelButton.Size
=
new
Size(
5
,
5
);
30
cancelButton.Location
=
new
Point(
-
10
,
-
10
);
31
cancelButton.Click
+=
new
EventHandler(cancelButton_Click);
32
Controls.Add(cancelButton);
33
cancelButton.TabIndex
=
0
;
34
this
.CancelButton
=
cancelButton;
35
}
36
37
byte
max
=
40
;
38
Panel[] panel
=
new
Panel[
40
];
39
Color[] color
=
new
Color[
40
]
{
40
//
row 1
41
Color.FromArgb(
0
,
0
,
0
), Color.FromArgb(
153
,
51
,
0
),Color.FromArgb(
51
,
51
,
0
), Color.FromArgb(
0
,
51
,
0
),Color.FromArgb(
0
,
51
,
102
), Color.FromArgb(
0
,
0
,
128
),
42
43
Color.FromArgb(
51
,
51
,
153
), Color.FromArgb(
51
,
51
,
51
),
44
//
row 2
45
Color.FromArgb(
128
,
0
,
0
), Color.FromArgb(
255
,
102
,
0
),
46
Color.FromArgb(
128
,
128
,
0
), Color.FromArgb(
0
,
128
,
0
),
47
Color.FromArgb(
0
,
128
,
128
), Color.FromArgb(
0
,
0
,
255
),
48
Color.FromArgb(
102
,
102
,
153
), Color.FromArgb(
128
,
128
,
128
),
49
//
row 3
50
Color.FromArgb(
255
,
0
,
0
), Color.FromArgb(
255
,
153
,
0
),
51
Color.FromArgb(
153
,
204
,
0
), Color.FromArgb(
51
,
153
,
102
),
52
Color.FromArgb(
51
,
204
,
204
), Color.FromArgb(
51
,
102
,
255
),
53
Color.FromArgb(
128
,
0
,
128
), Color.FromArgb(
153
,
153
,
153
),
54
//
row 4
55
Color.FromArgb(
255
,
0
,
255
), Color.FromArgb(
255
,
204
,
0
),
56
Color.FromArgb(
255
,
255
,
0
), Color.FromArgb(
0
,
255
,
0
),
57
Color.FromArgb(
0
,
255
,
255
), Color.FromArgb(
0
,
204
,
255
),
58
Color.FromArgb(
153
,
51
,
102
), Color.FromArgb(
192
,
192
,
192
),
59
//
row 5
60
Color.FromArgb(
255
,
153
,
204
), Color.FromArgb(
255
,
204
,
153
),
61
Color.FromArgb(
255
,
255
,
153
), Color.FromArgb(
204
,
255
,
204
),
62
Color.FromArgb(
204
,
255
,
255
), Color.FromArgb(
153
,
204
,
255
),
63
Color.FromArgb(
204
,
153
,
255
), Color.FromArgb(
255
,
255
,
255
)
64
}
;
65
66
string
[] colorName
=
new
string
[
40
]
67
{
68
"
Black
"
,
"
Brown
"
,
"
Olive Green
"
,
"
Dark Green
"
,
"
Dark Teal
"
,
"
Dark Blue
"
,
"
Indigo
"
,
"
Gray-80%
"
,
"
Dark Red
"
,
"
Orange
"
,
69
"
Dark Yellow
"
,
"
Green
"
,
"
Teal
"
,
"
Blue
"
,
"
Blue-Gray
"
,
"
Gray-50%
"
,
"
Red
"
,
"
Light Orange
"
,
"
Lime
"
,
"
Sea Green
"
,
"
Aqua
"
,
70
"
Light Blue
"
,
"
Violet
"
,
"
Gray-40%
"
,
"
Pink
"
,
"
Gold
"
,
"
Yellow
"
,
"
Bright Green
"
,
"
Turquoise
"
,
"
Sky Blue
"
,
"
Plum
"
,
71
"
Gray-25%
"
,
"
Rose
"
,
"
Tan
"
,
"
Light Yellow
"
,
"
Light Green
"
,
"
Light Turquoise
"
,
"
Pale Blue
"
,
"
Lavender
"
,
"
White
"
72
}
;
73
74
Button moreColorsButton
=
new
Button();
75
Button cancelButton
=
new
Button();
76
Color selectedColor;
77
78
public
Color Color
79
{
80
get
{
return
selectedColor;}
81
}
82
83
void
BuildPalette()
84
{
85
byte
pwidth
=
16
;
86
byte
pheight
=
16
;
87
byte
pdistance
=
2
;
88
byte
border
=
5
;
89
int
x
=
border, y
=
border;
90
ToolTip toolTip
=
new
ToolTip();
91
for
(
int
i
=
0
; i
<
max; i
++
)
92
{
93
panel[i]
=
new
Panel();
94
panel[i].Height
=
pwidth;
95
panel[i].Width
=
pheight;
96
panel[i].Location
=
new
Point(x, y);
97
toolTip.SetToolTip(panel[i], colorName[i]);
98
this
.Controls.Add(panel[i]);
99
if
(x
<
(
7
*
(pwidth
+
pdistance)))
100
x
+=
pwidth
+
pdistance;
101
else
102
{
103
x
=
border;
104
y
+=
pheight
+
pdistance;
105
}
106
panel[i].BackColor
=
color[i];
107
panel[i].MouseEnter
+=
new
EventHandler(OnMouseEnterPanel);
108
panel[i].MouseLeave
+=
new
EventHandler(OnMouseLeavePanel);
109
panel[i].MouseDown
+=
new
MouseEventHandler(OnMouseDownPanel);
110
panel[i].MouseUp
+=
new
MouseEventHandler(OnMouseUpPanel);
111
panel[i].Paint
+=
new
PaintEventHandler(OnPanelPaint);
112
}
113
}
114
115
void
moreColorsButton_Click(
object
sender, System.EventArgs e)
116
{
117
ColorDialog colDialog
=
new
ColorDialog();
118
colDialog.FullOpen
=
true
;
119
colDialog.ShowDialog();
120
selectedColor
=
colDialog.Color;
121
colDialog.Dispose();
122
Close();
123
}
124
125
void
cancelButton_Click(
object
sender, System.EventArgs e)
126
{
127
Close();
128
}
129
130
void
OnMouseEnterPanel(
object
sender, EventArgs e)
131
{
132
DrawPanel(sender,
1
);
133
}
134
135
void
OnMouseLeavePanel(
object
sender, EventArgs e)
136
{
137
DrawPanel(sender,
0
);
138
}
139
140
void
OnMouseDownPanel(
object
sender, MouseEventArgs e)
141
{
142
DrawPanel(sender,
2
);
143
}
144
145
void
OnMouseUpPanel(
object
sender, MouseEventArgs e)
146
{
147
Panel panel
=
(Panel)sender;
148
selectedColor
=
panel.BackColor;
149
Close();
150
}
151
152
void
DrawPanel(
object
sender,
byte
state)
153
{
154
Panel panel
=
(Panel)sender;
155
Graphics g
=
panel.CreateGraphics();
156
Pen pen1, pen2;
157
if
(state
==
1
)
//
mouse over
158
{
159
pen1
=
new
Pen( SystemColors.ControlLightLight );
160
pen2
=
new
Pen( SystemColors. ControlDarkDark);
161
}
162
else
if
(state
==
2
)
//
clicked
163
{
164
pen1
=
new
Pen( SystemColors.ControlDarkDark );
165
pen2
=
new
Pen( SystemColors.ControlLightLight );
166
}
167
else
//
neutral
168
{
169
pen1
=
new
Pen( SystemColors.ControlDark );
170
pen2
=
new
Pen( SystemColors.ControlDark );
171
}
172
Rectangle r
=
panel.ClientRectangle;
173
Point p1
=
new
Point( r.Left, r.Top );
//
top left
174
Point p2
=
new
Point( r.Right
-
1
, r.Top );
//
top right
175
Point p3
=
new
Point( r.Left, r.Bottom
-
1
);
//
bottom left
176
Point p4
=
new
Point( r.Right
-
1
, r.Bottom
-
1
);
//
bottom right
177
g.DrawLine( pen1, p1, p2 );
178
g.DrawLine( pen1, p1, p3 );
179
g.DrawLine( pen2, p2, p4 );
180
g.DrawLine( pen2, p3, p4 );
181
}
182
183
void
OnPanelPaint(Object sender, PaintEventArgs e)
184
{
185
DrawPanel(sender,
0
);
186
}
187
}
188
}
Feedback
# re: MS Office Color Picker颜色拾取器小程序! 回复 更多评论
2006-06-18 15:33 by
|