<?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; Drawmode</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/drawmode/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>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>

