<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>dotUpdate() &#187; C#</title>
	<atom:link href="http://dotupdate.wordpress.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://dotupdate.wordpress.com</link>
	<description>Useful information about C# and .Net</description>
	<lastBuildDate>Mon, 28 Jan 2008 13:18:34 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='dotupdate.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/7f71844728c1706e14f53bc26005a0d7?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>dotUpdate() &#187; C#</title>
		<link>http://dotupdate.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dotupdate.wordpress.com/osd.xml" title="dotUpdate()" />
		<item>
		<title>Find the color of a point in a LinearGradientBrush</title>
		<link>http://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/</link>
		<comments>http://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 12:54:22 +0000</pubDate>
		<dc:creator>dotupdate</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/</guid>
		<description><![CDATA[I became intrigued by the problem of finding the color at any point of a rectangle that has been filled with a LinearGradientBrush.&#160; There is are techniques for doing this by essentially sampling the pixel at a rendered point but I wanted to approach the problem algorithmically.
I developed the following method which receives a rectangle [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=24&subd=dotupdate&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I became intrigued by the problem of finding the color at any point of a rectangle that has been filled with a LinearGradientBrush.&nbsp; There is are techniques for doing this by essentially sampling the pixel at a rendered point but I wanted to approach the problem algorithmically.</p>
<p>I developed the following method which receives a rectangle object that has been filled with a LinearGradientBrush and a point relative to the upper left corner of the rectangle and returns the calculated color at that point.&nbsp; There are no restrictions on the Start/Stop Points or the number of GradientStops.&nbsp; The ColorInterpolationMode can be either SRgbLinearInterpolation (default) or ScRgbLinearInterpolation.&nbsp; The GradientSpreadMethod is required to be the default (Pad).</p>
<p>There are two methods below:</p>
<p>Color GetColorAtPoint(Rectangle r, Point p) &#8211; finds the color at any point of a LinearGradientBrush filled rectangle.</p>
<p>private Double dist(Point px, Point po, Point pf) &#8211; helper method for GetColorAtPoint.</p>
<p>To use, copy both methods to your class and call GetColorAtPoint() with a rectangle and point.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">//Calculates the color of a point in a rectangle that is filled</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">//with a LinearGradientBrush.</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">private</span> Color GetColorAtPoint(Rectangle theRec, Point thePoint)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Get properties</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    LinearGradientBrush br = (LinearGradientBrush)theRec.Fill;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> y3 = thePoint.Y;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> x3 = thePoint.X;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> x1 = br.StartPoint.X * theRec.ActualWidth;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> y1 = br.StartPoint.Y * theRec.ActualHeight;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    Point p1 = <span style="color:#0000ff;">new</span> Point(x1, y1); <span style="color:#008000;">//Starting point</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> x2 = br.EndPoint.X * theRec.ActualWidth;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> y2 = br.EndPoint.Y * theRec.ActualHeight;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    Point p2 = <span style="color:#0000ff;">new</span> Point(x2, y2);  <span style="color:#008000;">//End point</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Calculate intersecting points </span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    Point p4 = <span style="color:#0000ff;">new</span> Point(); <span style="color:#008000;">//with tangent</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">if</span> (y1 == y2) <span style="color:#008000;">//Horizontal case</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        p4 = <span style="color:#0000ff;">new</span> Point(x3, y1);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span> (x1 == x2) <span style="color:#008000;">//Vertical case</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        p4 = <span style="color:#0000ff;">new</span> Point(x1, y3);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">else</span> <span style="color:#008000;">//Diagnonal case</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">double</span> m = (y2 - y1) / (x2 - x1);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">double</span> m2 = -1 / m;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">double</span> b = y1 - m * x1;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">double</span> c = y3 - m2 * x3;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">double</span> x4 = (c - b) / (m - m2);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">double</span> y4 = m * x4 + b;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        p4 = <span style="color:#0000ff;">new</span> Point(x4, y4);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Calculate distances relative to the vector start</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> d4 = dist(p4, p1, p2);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> d2 = dist(p2, p1, p2);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> x = d4 / d2;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Clip the input if before or after the max/min offset values</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> max = br.GradientStops.Max(n =&gt; n.Offset);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">if</span> (x &gt; max)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        x = max;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> min = br.GradientStops.Min(n =&gt; n.Offset);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">if</span> (x &lt; min)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        x = min;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Find gradient stops that surround the input value</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    GradientStop gs0 = br.GradientStops.Where(n =&gt; n.Offset &lt;= x).OrderBy(n =&gt; n.Offset).Last();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    GradientStop gs1 = br.GradientStops.Where(n =&gt; n.Offset &gt;= x).OrderBy(n =&gt; n.Offset).First();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">float</span> y = 0f;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">if</span> (gs0.Offset != gs1.Offset)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        y = (<span style="color:#0000ff;">float</span>)((x - gs0.Offset) / (gs1.Offset - gs0.Offset));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Interpolate color channels</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    Color cx = <span style="color:#0000ff;">new</span> Color();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">if</span> (br.ColorInterpolationMode == ColorInterpolationMode.ScRgbLinearInterpolation)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">float</span> aVal = (gs1.Color.ScA - gs0.Color.ScA) * y + gs0.Color.ScA;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">float</span> rVal = (gs1.Color.ScR - gs0.Color.ScR) * y + gs0.Color.ScR;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">float</span> gVal = (gs1.Color.ScG - gs0.Color.ScG) * y + gs0.Color.ScG;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">float</span> bVal = (gs1.Color.ScB - gs0.Color.ScB) * y + gs0.Color.ScB;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        cx = Color.FromScRgb(aVal, rVal, gVal, bVal);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">else</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">byte</span> aVal = (<span style="color:#0000ff;">byte</span>)((gs1.Color.A - gs0.Color.A) * y + gs0.Color.A);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">byte</span> rVal = (<span style="color:#0000ff;">byte</span>)((gs1.Color.R - gs0.Color.R) * y + gs0.Color.R);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">byte</span> gVal = (<span style="color:#0000ff;">byte</span>)((gs1.Color.G - gs0.Color.G) * y + gs0.Color.G);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">byte</span> bVal = (<span style="color:#0000ff;">byte</span>)((gs1.Color.B - gs0.Color.B) * y + gs0.Color.B);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        cx = Color.FromArgb(aVal, rVal, gVal, bVal);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">return</span> cx;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">//Helper method for GetColorAtPoint</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">//Returns the signed magnitude of a point on a vector with origin po and pointing to pf</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">double</span> dist(Point px, Point po, Point pf)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">double</span> d = Math.Sqrt((px.Y - po.Y) * (px.Y - po.Y) + (px.X - po.X) * (px.X - po.X));</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">if</span> (((px.Y &lt; po.Y) &amp;&amp; (pf.Y &gt; po.Y)) ||</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        ((px.Y &gt; po.Y) &amp;&amp; (pf.Y &lt; po.Y)) ||</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        ((px.Y == po.Y) &amp;&amp; (px.X &lt; po.X) &amp;&amp; (pf.X &gt; po.X)) ||</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        ((px.Y == po.Y) &amp;&amp; (px.X &gt; po.X) &amp;&amp; (pf.X &lt; po.X)))</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">        d = -d;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">return</span> d;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<p>The method works by projecting the input point onto the vector that is described by the LinearGradientBrush Start/Stop points.&nbsp; There are special cases for horizontal and vertical lines.&nbsp; The width of the line is calculated as well as the relative distance of the projected point from the StartPoint (using the dist() method).&nbsp; The GradientStops are ordered and two stops are found that are the closest the projected point.&nbsp; The color channel values are interpolated based on the relative position of the projected point and these two stops.&nbsp; The values are assembled into a color and returned.</p>
<p>You can download a demo of this method <a href="http://home.comcast.net/~boddie/HelpWithColorPick.zip">here.</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dotupdate.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dotupdate.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotupdate.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotupdate.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotupdate.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotupdate.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotupdate.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotupdate.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotupdate.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotupdate.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotupdate.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotupdate.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=24&subd=dotupdate&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37b04d480ecd15e5890aa8cd26eb184a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotupdate</media:title>
		</media:content>
	</item>
		<item>
		<title>Generating Reports in Visual C# 2008 Express Edition</title>
		<link>http://dotupdate.wordpress.com/2008/01/03/generating-reports-in-visual-c-2008-express-edition/</link>
		<comments>http://dotupdate.wordpress.com/2008/01/03/generating-reports-in-visual-c-2008-express-edition/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 00:18:15 +0000</pubDate>
		<dc:creator>dotupdate</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://dotupdate.wordpress.com/2008/01/03/generating-reports-in-visual-c-2008-express-edition/</guid>
		<description><![CDATA[A common question on the MSDN C# Express forum is how do I generate reports?&#160; That is, how does one get a printout of data?&#160; The Standard and higher editions of Visual Studio have reporting services that allow reports to be easily designed in a WYSIWYG way.&#160; But Express users must either buy a third [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=21&subd=dotupdate&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A common question on the MSDN C# Express forum is how do I generate reports?&nbsp; That is, how does one get a printout of data?&nbsp; The Standard and higher editions of Visual Studio have reporting services that allow reports to be easily designed in a WYSIWYG way.&nbsp; But Express users must either buy a third party application (à la Crystal Reports&#8211;about $300 USD) or programmatically create the report using C# and GDI+ Classes.</p>
<p>Now with Visual C# 2008 Express Edition, there is a new option.&nbsp; Windows Presentation Foundation (WPF) provides a set of classes for converting markup (XAML) to Microsoft&#8217;s XML Page Specification (XPS).&nbsp; XPS documents can then be printed directly from your application or saved an viewed and printed by other applications and platforms.</p>
<p>With this system, there are a couple of options:&nbsp; First, you can specify the report document directly in C# code much like you would using GDI+.&nbsp; That is, you could place a textBlock or graphic at a specific x,y coordinate on a page using the properties of these elements.&nbsp; The second option is almost as good as having a report designer like in the higher Visual Studio editions.&nbsp; You can use the designer in Visual Studio to layout your report in a WPF grid so you can see exactly how your report should look when it is rendered.&nbsp; Then it is a very simple matter to pass the name of this grid to XPS generating classes for printing or saving.</p>
<p>Printing and XPS in WPF are covered thoroughly in Chapter 15 of <a href="http://www.oreilly.com/catalog/9780596510374/">Sells &amp; Griffiths, Programming WPF, O&#8221;Reilly.</a></p>
<p>The following example shows the routine for saving a grid1 (and all that it contains) to an XPS file.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> button1_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)
{
    Microsoft.Win32.SaveFileDialog dialog = <span style="color:#0000ff;">new</span> Microsoft.Win32.SaveFileDialog();
    <span style="color:#0000ff;">if</span> (dialog.ShowDialog() == <span style="color:#0000ff;">true</span>)
    {
        <span style="color:#0000ff;">string</span> xpsOutputPath = dialog.FileName;
        <span style="color:#0000ff;">using</span> (XpsDocument xpsFile = <span style="color:#0000ff;">new</span> XpsDocument(xpsOutputPath, FileAccess.Write))
        {
            XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(xpsFile);
            xpsdw.Write(grid1);
        }
    }

}</pre>
</div>
<p>&nbsp;</p>
<p>This routine requires adding a couple of references to the solution: ReachFramework and System.Printing.&nbsp; You will need to also add some namespace references:</p>
<p>using System.Windows.Xps;<br />using System.IO;<br />using Microsoft.Win32;<br />using System.Windows.Xps.Packaging;</p>
<p>The code for printing directly is not much more complex and is described in the book.</p>
<p>With WPF one should be able to quickly and easily create a rich looking data report that can be printed or saved.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dotupdate.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dotupdate.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotupdate.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotupdate.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotupdate.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotupdate.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotupdate.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotupdate.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotupdate.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotupdate.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotupdate.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotupdate.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=21&subd=dotupdate&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotupdate.wordpress.com/2008/01/03/generating-reports-in-visual-c-2008-express-edition/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37b04d480ecd15e5890aa8cd26eb184a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotupdate</media:title>
		</media:content>
	</item>
		<item>
		<title>How to add a WPF control library template to Visual C# Express 2008</title>
		<link>http://dotupdate.wordpress.com/2007/12/05/how-to-add-a-wpf-control-library-template-to-visual-c-express-2008/</link>
		<comments>http://dotupdate.wordpress.com/2007/12/05/how-to-add-a-wpf-control-library-template-to-visual-c-express-2008/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 14:05:48 +0000</pubDate>
		<dc:creator>dotupdate</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://dotupdate.wordpress.com/2007/12/05/how-to-add-a-wpf-control-library-template-to-visual-c-express-2008/</guid>
		<description><![CDATA[Visual C# Express 2008 does not come with a project template for creating custom controls (.dll files).&#160; You can create your own template by following these steps:

1. Open Visual C# Express 2008. 
2. Create New WPF Application with name: MyLibrary 
3. Project &#62; Add User Control 
4. In Solution Explorer, Delete Window1.xaml and App.xaml (the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=19&subd=dotupdate&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Visual C# Express 2008 does not come with a project template for creating custom controls (.dll files).&nbsp; You can create your own template by following these steps:</p>
<ol>
<li>1. Open Visual C# Express 2008. </li>
<li>2. Create New WPF Application with name: MyLibrary </li>
<li>3. Project &gt; Add User Control </li>
<li>4. In Solution Explorer, Delete Window1.xaml and App.xaml (the corresponding .cs files should be deleted by this step) </li>
<li>5. Project &gt; MyLibrary Properties &gt; Application &gt; Output Type = Class Library </li>
<li>6. Build Solution.&nbsp; There should be no errors and the bin/Release folder should have a MyLibrary.dll file </li>
<li>7. File &gt; Export Template </li>
<li>8. Select Project Template then Next </li>
<li>9. Under Template Options change name to: WPF Control Library and Description: Create WPF Control .dll</li>
</ol>
<p>The next time you open VS, you will find your newly created template ready to use.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dotupdate.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dotupdate.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotupdate.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotupdate.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotupdate.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotupdate.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotupdate.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotupdate.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotupdate.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotupdate.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotupdate.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotupdate.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=19&subd=dotupdate&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotupdate.wordpress.com/2007/12/05/how-to-add-a-wpf-control-library-template-to-visual-c-express-2008/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37b04d480ecd15e5890aa8cd26eb184a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotupdate</media:title>
		</media:content>
	</item>
		<item>
		<title>Color Picker for WPF</title>
		<link>http://dotupdate.wordpress.com/2007/12/03/color-picker-for-wpf/</link>
		<comments>http://dotupdate.wordpress.com/2007/12/03/color-picker-for-wpf/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 13:06:07 +0000</pubDate>
		<dc:creator>dotupdate</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://dotupdate.wordpress.com/2007/12/03/color-picker-for-wpf/</guid>
		<description><![CDATA[I needed a color picker for WPF and found a simple design by Lee Brimelow here.
I used a bitmap image of a pallet from the Windows Forms ColorPicker dialog.
 
The problem is that it is not a complete color picker.&#160; The missing variable is luminosity.
I found complete ColorPicker here.
       [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=18&subd=dotupdate&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I needed a color picker for WPF and found a simple design by Lee Brimelow <a href="http://thewpfblog.com/?p=62">here</a>.</p>
<p>I used a bitmap image of a pallet from the Windows Forms ColorPicker dialog.</p>
<p><a href="http://dotupdate.files.wordpress.com/2007/12/colorpick.png"><img style="border-width:0;" height="191" alt="ColorPick" src="http://dotupdate.files.wordpress.com/2007/12/colorpick-thumb.png?w=178&#038;h=191" width="178" border="0"></a> </p>
<p>The problem is that it is not a complete color picker.&nbsp; The missing variable is luminosity.</p>
<p>I found complete ColorPicker <a href="http://msdn2.microsoft.com/en-us/library/ms771620.aspx">here</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dotupdate.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dotupdate.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotupdate.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotupdate.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotupdate.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotupdate.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotupdate.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotupdate.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotupdate.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotupdate.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotupdate.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotupdate.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=18&subd=dotupdate&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotupdate.wordpress.com/2007/12/03/color-picker-for-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37b04d480ecd15e5890aa8cd26eb184a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotupdate</media:title>
		</media:content>

		<media:content url="http://dotupdate.files.wordpress.com/2007/12/colorpick-thumb.png" medium="image">
			<media:title type="html">ColorPick</media:title>
		</media:content>
	</item>
		<item>
		<title>Cider Tricks: Menus, TabPages, ToolBars</title>
		<link>http://dotupdate.wordpress.com/2007/11/30/cider-tricks-menus-tabpages-toolbars-2/</link>
		<comments>http://dotupdate.wordpress.com/2007/11/30/cider-tricks-menus-tabpages-toolbars-2/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 16:21:00 +0000</pubDate>
		<dc:creator>dotupdate</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Cider]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://dotupdate.wordpress.com/2007/11/30/cider-tricks-menus-tabpages-toolbars-2/</guid>
		<description><![CDATA[The frustrating thing about the WPF Designer in VS2008 (a.k.a. &#8220;Cider&#8221;) is that it does not support drag and drop placement of items for every control. The first three that I encountered were menus, toolbars&#160;and laying out controls on a tab page. The IDE does have some capability to facilitate the design of these items [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=15&subd=dotupdate&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The frustrating thing about the WPF Designer in VS2008 (a.k.a. &#8220;Cider&#8221;) is that it does not support drag and drop placement of items for every control. The first three that I encountered were menus, toolbars&nbsp;and laying out controls on a tab page. The IDE does have some capability to facilitate the design of these items that don&#8217;t require exclusive XAML coding. You just have to know the techniques to use them.<br />
<h5>Menus</h5>
<p>While you can add MenuItem to the toolbox, you can not drag it to the content portion of a Menu control in the designer. The easy way to create Menus is as follows:
<p>1. Drag a Menu control from the toolbox onto the window.
<p>2. Select the Menu control and find the Items property in the Property window. Click on the (&#8230;) icon. This will bring up the Collection Editor dialog.
<p>3. Use it to add MenuItems. You can edit the properties of each item (like the Header property) as well as add sub-items by clicking on the Items property of the MenuItem. For the sub-items, you can also add a separator.<br />
<h5>ToolBars</h5>
<p>Items in a ToolBar can only be added with the XAML editor. Once added, you can edit and move them using the Collection Editor for the ToolBar.<br />
<h5>TabControl</h5>
<p>You cannot layout controls directly on a TabItem for a TabControl. There are two tricks that are required: use a Grid panel and using the SelectedIndex to put each page in view for layout.
<p>1. Drag a TabControl from the toolbox onto the window.
<p>2. Using the Items propery in the Property window, add your TabItems and enter the Header properties for each one.
<p>3. In the XAML editor, add a Grid to each TabItem like this:</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">&lt;TabItem&gt;
    &lt;Grid/&gt;
&lt;/TabItem&gt;
</pre>
</div>
<p>4. Select the TabControl and locate the SelectedIndex property. Change the index to the page you want to layout. </p>
<p>5. Drag and drop items from the toolbox onto the Grid of the TabItem.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dotupdate.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dotupdate.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotupdate.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotupdate.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotupdate.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotupdate.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotupdate.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotupdate.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotupdate.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotupdate.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotupdate.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotupdate.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=15&subd=dotupdate&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotupdate.wordpress.com/2007/11/30/cider-tricks-menus-tabpages-toolbars-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37b04d480ecd15e5890aa8cd26eb184a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotupdate</media:title>
		</media:content>
	</item>
		<item>
		<title>How to make an icon</title>
		<link>http://dotupdate.wordpress.com/2007/08/26/how-to-make-an-icon/</link>
		<comments>http://dotupdate.wordpress.com/2007/08/26/how-to-make-an-icon/#comments</comments>
		<pubDate>Sun, 26 Aug 2007 11:43:53 +0000</pubDate>
		<dc:creator>dotupdate</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://dotupdate.wordpress.com/2007/08/26/how-to-make-an-icon/</guid>
		<description><![CDATA[Apparently, .Net does not provide a good set of classes to create icons programmatically.&#160; In helping someone on a forum, I ran across a free tool for image processing that does a great job.
The technique uses a free .dll called FreeImage. I gave it a try and with the help of a wrapper found in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=9&subd=dotupdate&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Apparently, .Net does not provide a good set of classes to create icons programmatically.&nbsp; In helping someone on a forum, I ran across a free tool for image processing that does a great job.</p>
<p>The technique uses a free .dll called <a href="http://freeimage.sourceforge.net/index.html">FreeImage</a>. I gave it a try and with the help of a wrapper found in <a href="http://www.codeproject.com/csharp/FreeImageCSWrapper.asp?df=100">CodeProject</a> was able to convert a .bmp file to a .ico file.
<p>Here are the steps:
<p>1. Download the FreeImage .dll from <a href="http://freeimage.sourceforge.net/download.html">here</a>.
<p>2. Copy the .dll into the bin/Debug and/or bin/Release folder in your project
<p>3. Add an Enum and FreeImage Class to your project (shown in the example below).
<p>4. Use three calls to the functions in FreeImage: load the bitmap file, save in icon format, release the resource.
<p>The following example loads a .bmp into FreeImage and saves it back as a .ico file. It includes the required Enum and FreeImage Class. (Requires using System.Runtime.InteropServices; )</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, 'Courier New', courier, monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">class</span> Program
{
    <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> Main(<span style="color:#0000ff;">string</span>[] args)
    {
        <span style="color:#0000ff;">int</span> handle = FreeImage.FreeImage_Load(
            FIF.FIF_BMP,
            <span style="color:#006080;">@"C:\Documents and Settings\User\Desktop\myBmp.bmp"</span>,
            0);

        FreeImage.FreeImage_Save(
            FIF.FIF_ICO,
            handle,
            <span style="color:#006080;">@"C:\Documents and Settings\User\Desktop\new.ico"</span>,
            0);

        FreeImage.FreeImage_Unload(handle);         

    }
}

<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">enum</span> FIF
{
    FIF_UNKNOWN = -1,
    FIF_BMP = 0,
    FIF_ICO = 1,
    FIF_JPEG = 2,
    FIF_JNG = 3,
    FIF_KOALA = 4,
    FIF_LBM = 5,
    FIF_MNG = 6,
    FIF_PBM = 7,
    FIF_PBMRAW = 8,
    FIF_PCD = 9,
    FIF_PCX = 10,
    FIF_PGM = 11,
    FIF_PGMRAW = 12,
    FIF_PNG = 13,
    FIF_PPM = 14,
    FIF_PPMRAW = 15,
    FIF_RAS = 16,
    FIF_TARGA = 17,
    FIF_TIFF = 18,
    FIF_WBMP = 19,
    FIF_PSD = 20,
    FIF_CUT = 21,
    FIF_IFF = FIF_LBM,
    FIF_XBM = 22,
    FIF_XPM = 23
}
<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> FreeImage
{
     [DllImport(<span style="color:#006080;">"FreeImage.dll"</span>)]
     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">extern</span> <span style="color:#0000ff;">int</span> FreeImage_Load(FIF format,
                    <span style="color:#0000ff;">string</span> filename, <span style="color:#0000ff;">int</span> flags);

     [DllImport(<span style="color:#006080;">"FreeImage.dll"</span>)]
     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">extern</span> <span style="color:#0000ff;">void</span> FreeImage_Unload(<span style="color:#0000ff;">int</span> handle);

     [DllImport(<span style="color:#006080;">"FreeImage.dll"</span>)]
     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">extern</span> <span style="color:#0000ff;">bool</span> FreeImage_Save(FIF format,
        <span style="color:#0000ff;">int</span> handle, <span style="color:#0000ff;">string</span> filename, <span style="color:#0000ff;">int</span> flags);
}</pre>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dotupdate.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dotupdate.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotupdate.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotupdate.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotupdate.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotupdate.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotupdate.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotupdate.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotupdate.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotupdate.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotupdate.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotupdate.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=9&subd=dotupdate&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotupdate.wordpress.com/2007/08/26/how-to-make-an-icon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37b04d480ecd15e5890aa8cd26eb184a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotupdate</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 411</title>
		<link>http://dotupdate.wordpress.com/2007/08/16/visual-studio-411/</link>
		<comments>http://dotupdate.wordpress.com/2007/08/16/visual-studio-411/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 14:14:10 +0000</pubDate>
		<dc:creator>dotupdate</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://dotupdate.wordpress.com/2007/08/16/visual-studio-411/</guid>
		<description><![CDATA[Visual Studio has a powerful array of features that can greatly boost productivity&#8211;especially for new programmers who may not have a full grasp of the .Net framework.&#160; While the C# language itself&#160;is quite compact and comprehensible, the number of classes available in the .Net framework is almost mind boggling.&#160; How is a newcomer supposed to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=8&subd=dotupdate&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Visual Studio has a powerful array of features that can greatly boost productivity&#8211;especially for new programmers who may not have a full grasp of the .Net framework.&nbsp; While the C# language itself&nbsp;is quite compact and comprehensible, the number of classes available in the .Net framework is almost mind boggling.&nbsp; How is a newcomer supposed to remember it all?</p>
<p>The good news is that with Visual Studio you don&#8217;t have to.&nbsp; You just need to know how to get the information (&#8216;411&#8242;) when you need it.&nbsp; Here are the most helpful features for me:</p>
<h4><font color="#333333">Intellesense</font></h4>
<p>There are three big productivity enhancements that I get out of Intellesense.&nbsp; First, I use it to help find out what is possible with an object.&nbsp; By typing a &#8216;.&#8217; after the object name in a statement, the Intellesense drop down shows all of the properties and methods that are available to me.&nbsp; Icons by the names of the members indicate the type (properties: a page with a hand, methods: a diamond, events: a lightning bolt).&nbsp; Second, selecting one of the members gives a brief synopsis which includes the type of value returned and the arguments that are expected.&nbsp; After selecting, if I type another delimiter (a space, a dot, a parenthesis), Intellesense will&nbsp; enter the code for me reducing the possibility of making a typographical mistake.&nbsp; For methods, entering the open parenthesis results in Intellesense showing the possible overloads (different argument possibilities).&nbsp; Intellesense is almost like having an expert programmer sitting over your shoulder advising you every step of the way.</p>
<h4><font color="#333333">Dynamic Help</font></h4>
<p>Dynamic help is a way of quickly getting to more information from the MSDN documentation file.&nbsp; Turn this feature on using menu Help &gt; Dynamic Help.&nbsp; Now, when you click on an item in the code view or the designer view, a list of links to the Help documentation is presented.&nbsp; Click on a link and most likely you will get exactly the information you are seeking.</p>
<h4><font color="#333333">MSDN Documentation</font></h4>
<p>Newcomers need to understand the format of the help documentation so as not to be overwhelmed by its scope.&nbsp; Every class typically has the following organization: an overview page, a members page listing all properties, methods and events, finally leading to pages for individual members.&nbsp; More often than not, the individual members page will offer an example that can be adapted or even copied directly into the application.</p>
<h4><font color="#333333">Index</font></h4>
<p>For me, the most useful way of getting to the information in the documentation (outside of dynamic help) is to use the Index: menu Help &gt; Index.&nbsp; Also available are &#8216;Search&#8217; and &#8216;Content&#8217; but &#8216;Index&#8217; works best for me.</p>
<h4><font color="#333333">How do I</font></h4>
<p>Help &gt; How do I can also lead to helpful articles in the documentation for doing the most common tasks like File IO or drawing.</p>
<h4><font color="#333333">Getting Help Online</font></h4>
<p>Outside of Visual Studio there is a wealth of information.&nbsp; If I have a question about a control or how to do something, chances are good that someone else has had the same problem and has already posted the solution.&nbsp; I usually fire up a search engine and put in a few keywords about the problem along with &#8216;msdn&#8217;.&nbsp; This biases the search to either the msdn documentation or one of the msdn forums.</p>
<p>For me, asking a question in an online forum is my option of last resort.&nbsp; Not that it is a bad thing to do but the time I spend using the other resources available is always a valuable learning experience in itself and can turn up nuggets that can be used in later projects.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dotupdate.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dotupdate.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotupdate.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotupdate.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotupdate.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotupdate.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotupdate.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotupdate.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotupdate.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotupdate.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotupdate.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotupdate.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotupdate.wordpress.com&blog=1510168&post=8&subd=dotupdate&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dotupdate.wordpress.com/2007/08/16/visual-studio-411/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37b04d480ecd15e5890aa8cd26eb184a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotupdate</media:title>
		</media:content>
	</item>
	</channel>
</rss>