-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwatch.cs
More file actions
104 lines (89 loc) · 3.01 KB
/
Swatch.cs
File metadata and controls
104 lines (89 loc) · 3.01 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ColourPickerComponents
{
public partial class Swatch : UserControl
{
private Rectangle paintArea;
private ContextMenu rclick;
private Color colour = Color.White;
private bool contextmenuenabled = false;
[DefaultValue(false), Category("Behaviour"), Description("Enable context menu - for copying current values")]
public bool ContextMenuEnabled
{
set
{
if (value != contextmenuenabled)
{
if (value)
{
this.ContextMenu = this.rclick;
}
else
{
this.ContextMenu = null;
}
this.contextmenuenabled = value;
}
}
get
{
return this.contextmenuenabled;
}
}
public Swatch()
{
InitializeComponent();
this.DoubleBuffered = true;
}
public void SetColour(Color Colour)
{
this.colour = Colour;
this.Refresh();
}
private void Swatch_Load(object sender, EventArgs e)
{
this.UpdatePaintArea();
SetupContextMenu();
}
private void SetupContextMenu()
{
this.rclick = new System.Windows.Forms.ContextMenu();
Menu.MenuItemCollection items = new Menu.MenuItemCollection(rclick);
this.rclick.MenuItems.Add(new MenuItem("Copy color to clipboard"));
this.rclick.MenuItems[0].Enabled = false;
this.rclick.MenuItems.Add(new MenuItem("...as R,G,B", this.CopyRGB));
this.rclick.MenuItems.Add(new MenuItem("...as #HEX", this.CopyHex));
}
private void CopyToClipboard(ColourHandler.ColourRepresentations format)
{
Clipboard.SetText(ColourHandler.FormatColourString(this.colour, format));
}
private void CopyRGB(object sender, EventArgs e)
{
this.CopyToClipboard(ColourHandler.ColourRepresentations.RGB);
}
private void CopyHex(object sender, EventArgs e)
{
this.CopyToClipboard(ColourHandler.ColourRepresentations.Hex);
}
private void Swatch_Resize(object sender, EventArgs e)
{
this.UpdatePaintArea();
}
private void UpdatePaintArea()
{
this.paintArea = new Rectangle(0, 0, this.Width, this.Height);
}
private void Swatch_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(this.colour), this.paintArea);
}
}
}