<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dotnet thoughts &#187; Color Picker</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/color-picker/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating color picker application in C#</title>
		<link>http://www.dotnetthoughts.net/2011/03/06/creating-color-picker-application-in-c/</link>
		<comments>http://www.dotnetthoughts.net/2011/03/06/creating-color-picker-application-in-c/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 08:03:01 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Color Picker]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1550</guid>
		<description><![CDATA[Yesterday I modified my blog&#8217;s theme. That time I thought about writing an application to pick color from any where in the screen like web page or application. I know there are some applications already out there in the market &#8230; <a href="http://www.dotnetthoughts.net/2011/03/06/creating-color-picker-application-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday I modified my blog&#8217;s theme. That time I thought about writing an application to pick color from any where in the screen like web page or application. I know there are some applications already out there in the market to do this. Yet again I thought of writing one. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The main challenges on the implementation of me </p>
<ul>
<li>How to get the mouse position when the mouse pointer is out of the Form. &#8211; I found one solution with GetCursorPos() WIN32 API function.
<pre class="brush: csharp; title: ; notranslate">
Point p = new Point();
GetCursorPos(ref p);
</pre>
</li>
<li>How to monitor the position of the Mouse Pointer &#8211; I couldn&#8217;t find easy solution for this(There is some solution like Hooking the mouse). So I added a timer control into the form, and in the Tick Event I called the GetCursorPos() function. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>The major challenge was Getting the color from the position, I searched net, and I found solution using GetPixel() API function.
<pre class="brush: csharp; title: ; notranslate">
IntPtr hdc = GetDC(IntPtr.Zero);
uint pixel = GetPixel(hdc, currentPoint.X, currentPoint.Y);
ReleaseDC(IntPtr.Zero, hdc);
</pre>
</li>
<li>The last challenge was to keep the Form always on top of other forms. Again I found solution using SetWindowPos() method.</li>
</ul>
<p>And here is the screenshot of color picker.</p>
<div id="attachment_1555" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/03/screenshot.png"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2011/03/screenshot-300x282.png" alt="ColorPicker - Screenshot" title="ColorPicker - Screenshot" width="300" height="282" class="size-medium wp-image-1555" /></a><p class="wp-caption-text">ColorPicker - Screenshot</p></div>
<p>You can download ColorPicker source from <a href='http://www.dotnetthoughts.net/wp-content/uploads/2011/03/ColorPicker.zip'>ColorPicker &#8211; Source Files</a></p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/08/25/how-to-disable-close-button-of-windows-forms-application/" title="Permanent link to How to disable Close button of Windows Forms Application">How to disable Close button of Windows Forms Application</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/09/26/how-to-make-a-form-stay-always-on-top/" title="Permanent link to How to make a form stay always on top">How to make a form stay always on top</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/03/03/update-multiple-elements-at-once-using-linq/" title="Permanent link to Update multiple elements at once using LINQ">Update multiple elements at once using LINQ</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/30/how-to-use-taskdialog-api-in-c/" title="Permanent link to How to use TaskDialog API in C#">How to use TaskDialog API in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/06/12/a-simple-splash-screen-in-c/" title="Permanent link to A Simple Splash screen in C#">A Simple Splash screen in C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/03/06/creating-color-picker-application-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Color Picker Dropdown using C#</title>
		<link>http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:05:52 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Color Picker]]></category>
		<category><![CDATA[Drawing]]></category>
		<category><![CDATA[Drawmode]]></category>
		<category><![CDATA[Dropdown]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=527</guid>
		<description><![CDATA[While playing around one of hobby project, I found there is a nice color picker dropdown available in WordPad, for setting the font color. I was using Windows Color Dialog. So I thought of implementing a WordPad like color picker. &#8230; <a href="http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While playing around one of hobby project, I found there is a nice color picker dropdown available in WordPad, for setting the font color. I was using Windows </p>
<p>Color Dialog. So I thought of implementing a WordPad like color picker. And I think I almost readed my goal. I need to try this in the Toolstrip dropdown too.</p>
<pre class="brush: csharp; title: ; notranslate">
//On the Form load I am loading the colors to the Dropdown.
//You can also bind the p to the Dropdown.
Type t = typeof(Color);
PropertyInfo[] p = t.GetProperties();
foreach (PropertyInfo item in p)
{
    if (item.PropertyType.FullName.Equals(&quot;System.Drawing.Color&quot;, StringComparison.CurrentCultureIgnoreCase))
    {
        this.comboBox1.Items.Add(item.Name);
    }
}
</pre>
<p>And I set the Dropdown&#8217;s DrawMode property to &#8220;OwnerDrawFixed&#8221;. And in the DrawItem event of the Dropdown I wrote the code.</p>
<pre class="brush: csharp; title: ; notranslate">
if (e.Index != -1)
{
    e.DrawBackground();
    e.Graphics.FillRectangle(GetCurrentBrush(comboBox1.Items[e.Index].ToString()), e.Bounds);
    Font f = comboBox1.Font;
    e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), f, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
    e.DrawFocusRectangle();
}
</pre>
<p>And the GetCurrentBrush() function returns the Brush for painting the rectangle. You can write the code in the DrawItem event too, but initialy I thought about setting the font color using the same color. But later that idea changed.</p>
<pre class="brush: csharp; title: ; notranslate">
private Brush GetCurrentBrush(string colorName)
{
    return new SolidBrush(Color.FromName(colorName));
}
</pre>
<p>One issue I found in this code is, for black color, I can&#8217;t see the color name. And here is the screenshot of Color Picker Dropdown running on my machine.</p>
<div id="attachment_529" class="wp-caption alignnone" style="width: 285px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/10/color_dropdown.PNG" alt="Color Picker Dropdown screenshot" title="Color Picker Dropdown screenshot" width="275" height="385" class="size-full wp-image-529" /><p class="wp-caption-text">Color Picker Dropdown screenshot</p></div>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2007/04/17/font-enumeration-in-vbnet/" title="Permanent link to Font Enumeration in VB.Net">Font Enumeration in VB.Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/10/18/how-to-add-simple-water-mark-to-images/" title="Permanent link to How to add simple water mark to images">How to add simple water mark to images</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/03/06/creating-color-picker-application-in-c/" title="Permanent link to Creating color picker application in C#">Creating color picker application in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2012/02/07/drive-combo-box-in-c/" title="Permanent link to Drive combo box in C#">Drive combo box in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/15/captcha-using-asp-net-and-c/" title="Permanent link to Captcha using ASP.Net and C#">Captcha using ASP.Net and C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

