diff --git a/colourpicker/colourpicker/MainForm.Designer.cs b/colourpicker/colourpicker/MainForm.Designer.cs index 6312284..65e477e 100644 --- a/colourpicker/colourpicker/MainForm.Designer.cs +++ b/colourpicker/colourpicker/MainForm.Designer.cs @@ -30,6 +30,7 @@ private void InitializeComponent() { this.colourPanel = new System.Windows.Forms.Panel(); this.colorLabel = new System.Windows.Forms.Label(); + this.tipLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // // colourPanel @@ -42,23 +43,38 @@ private void InitializeComponent() // // colorLabel // - this.colorLabel.Location = new System.Drawing.Point(243, 65); + this.colorLabel.Location = new System.Drawing.Point(243, 12); this.colorLabel.Name = "colorLabel"; - this.colorLabel.Size = new System.Drawing.Size(321, 103); + this.colorLabel.Size = new System.Drawing.Size(321, 101); this.colorLabel.TabIndex = 1; this.colorLabel.Text = "..."; // + // tipLabel + // + this.tipLabel.Location = new System.Drawing.Point(248, 143); + this.tipLabel.Name = "tipLabel"; + this.tipLabel.Size = new System.Drawing.Size(316, 81); + this.tipLabel.TabIndex = 2; + this.tipLabel.Text = "Ctrl + C to copy current colour. It only works if this window is being focused"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(576, 236); + this.Controls.Add(this.tipLabel); this.Controls.Add(this.colorLabel); this.Controls.Add(this.colourPanel); + this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.KeyPreview = true; this.MaximizeBox = false; this.MinimumSize = new System.Drawing.Size(600, 300); this.Name = "MainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "Colour Picker"; + this.TopMost = true; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown); this.ResumeLayout(false); } @@ -67,6 +83,7 @@ private void InitializeComponent() private System.Windows.Forms.Panel colourPanel; private System.Windows.Forms.Label colorLabel; + private System.Windows.Forms.Label tipLabel; } } diff --git a/colourpicker/colourpicker/MainForm.cs b/colourpicker/colourpicker/MainForm.cs index 426e9b5..02c1a7e 100644 --- a/colourpicker/colourpicker/MainForm.cs +++ b/colourpicker/colourpicker/MainForm.cs @@ -20,6 +20,7 @@ public MainForm() { InitializeComponent(); lastLocaion = Cursor.Position; + resetTip(); // Set a timer to update colour every 10ms Timer t = new Timer(); @@ -34,10 +35,16 @@ private void T_Tick(object sender, EventArgs e) Console.WriteLine(curr); // Same location don't update anything if (lastLocaion.X == curr.X && lastLocaion.Y == curr.Y) return; + lastLocaion = curr; // Update panel colour updateColour(GetColorAt(curr)); + resetTip(); + } + private void resetTip() + { + tipLabel.Text = "Ctrl + C to copy current colour\nIt only works if this window is being focused"; } /// @@ -51,7 +58,12 @@ private void updateColour(Color c) colourPanel.BackColor = c; // Get RGB and HEX string - colorLabel.Text = RGBConverter(c) + "\n" + HexConverter(c); + colorLabel.Text = getFormattedColour(c); + } + + private string getFormattedColour(Color c) + { + return RGBConverter(c) + "\n" + HexConverter(c); } /// @@ -59,7 +71,7 @@ private void updateColour(Color c) /// /// Colour /// A string like #123456 - private static string HexConverter(Color c) + private string HexConverter(Color c) { return string.Format("#{0}{1}{2}", c.R.ToString("X2"), c.G.ToString("X2"), c.B.ToString("X2")); } @@ -69,9 +81,9 @@ private static string HexConverter(Color c) /// /// Color /// A string like RGB(0, 0, 0) - private static string RGBConverter(Color c) + private string RGBConverter(Color c) { - return string.Format("RGB({0}, {1}, {2})\n", c.R, c.G, c.B); + return string.Format("RGB({0}, {1}, {2})", c.R, c.G, c.B); } [DllImport("user32.dll", SetLastError = true)] @@ -96,5 +108,14 @@ public static Color GetColorAt(Point p) ReleaseDC(desk, dc); return Color.FromArgb(255, (a >> 0) & 0xff, (a >> 8) & 0xff, (a >> 16) & 0xff); } + + private void MainForm_KeyDown(object sender, KeyEventArgs e) + { + if (e.Control && e.KeyCode == Keys.C) + { + Clipboard.SetText(getFormattedColour(currColour)); + tipLabel.Text = "Copied :)"; + } + } } }