<?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>projects @ bovendeur.org &#187; C#</title>
	<atom:link href="http://projects.bovendeur.org/category/projects/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://projects.bovendeur.org</link>
	<description>open source projects and more</description>
	<lastBuildDate>Wed, 22 Apr 2009 18:33:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Updated ExtProgressbar</title>
		<link>http://projects.bovendeur.org/2007/10/06/updated-extprogressbar/</link>
		<comments>http://projects.bovendeur.org/2007/10/06/updated-extprogressbar/#comments</comments>
		<pubDate>Sat, 06 Oct 2007 18:45:32 +0000</pubDate>
		<dc:creator>r-win</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://projects.bovendeur.org/2007/10/06/updated-extprogressbar/</guid>
		<description><![CDATA[The demo and source files added to the ExtProgressbar are updated to the correct version. Steve Medley notified me of the fact that he couldn&#8217;t change the orientation of the bar posted with the article. It seemed that the version posted with the article was a (very) old version, so I&#8217;ve updated the files to [...]]]></description>
			<content:encoded><![CDATA[<p>The demo and source files added to the ExtProgressbar are updated to the correct version. Steve Medley notified me of the fact that he couldn&#8217;t change the orientation of the bar posted with the article. It seemed that the version posted with the article was a (very) old version, so I&#8217;ve updated the files to the correct version. Steve, thank you!</p>
<p>Please note, the solution and project files in the archives are for Visual Studio 2008 beta 2.</p>
]]></content:encoded>
			<wfw:commentRss>http://projects.bovendeur.org/2007/10/06/updated-extprogressbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExtProgressBar</title>
		<link>http://projects.bovendeur.org/2007/07/05/extprogressbar/</link>
		<comments>http://projects.bovendeur.org/2007/07/05/extprogressbar/#comments</comments>
		<pubDate>Wed, 04 Jul 2007 22:28:32 +0000</pubDate>
		<dc:creator>r-win</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://bovendeur.org/2007/07/05/extprogressbar/</guid>
		<description><![CDATA[During the coding and testing of an application for one of my clients, I ran over and over against the wall using the .NET progressbar control. I missed a lot of properties to adjust the progressbar to the design of my application instead of the default Windows look &#8216;n feel. Properties like a smooth indicator, [...]]]></description>
			<content:encoded><![CDATA[<p>During the coding and testing of an application for one of my clients, I ran over and over against the wall using the .NET progressbar control. I missed a lot of properties to adjust the progressbar to the design of my application instead of the default Windows look &#8216;n feel. Properties like a smooth indicator, printing the progress inside the control and more control over the colors of both the background and the progressbar. After searching 
<a target="_blank" title="CodeProject"  href="http://www.codeproject.com" onclick="javascript:pageTracker._trackPageview('/external/www.codeproject.com');" >CodeProject</a>, I&#8217;ve found some nice contributions, but none fitted my requirements. That&#8217;s why I wrote my own.<span id="more-20"></span>  My first concern was the replacement of the existing progressbars in my application. Changing them to another progressbar should be as easy as change the declaration and initialization from</p>
<p><code>private System.Windows.Forms.ProgressBar progressBar = new System.Windows.Forms.ProgressBar(); </code></p>
<p>to</p>
<p><code>private ExtControls.ExtProgressBar progressBar = new ExtControls.ExtProgressBar();</code></p>
<p>To reach that goal, I wanted my control to inherit from the .NET progressbar. Unfortunately, Microsoft decided, in all it&#8217;s wisdom, that the ProgressBar  control should become a sealed class. Therefor, I had to create a new control from scratch, which implemented every property and every function of the original .NET progressbar.  
<a title="Extended Progressbar" rel="lightbox"  href="http://bovendeur.org/wordpress/wp-content/uploads/2007/07/extprogressbar.jpg" onclick="javascript:pageTracker._trackPageview('/external/bovendeur.org/wordpress/wp-content/uploads/2007/07/extprogressbar.jpg');" ><img border="0" align="right" alt="Extended Progressbar" title="Extended Progressbar" src="http://bovendeur.org/wordpress/wp-content/uploads/2007/07/extprogressbar.thumbnail.jpg" /></a></p>
<p>&nbsp;</p>
<h3>What does it do?</h3>
<p>As you should have guessed by now, the control is capable of drawing a progressbar in a lot of different ways. On the right is a screenshot with some of the possibilities of the control.</p>
<h3>Features</h3>
<ul>
<li>A smooth progressbar, as seen in the first progressbar in the screenshot.</li>
<li>A label inside the progressbar, which uses String.Format to insert the progress in percentages, the actual progress value, the minimum value and the maximum value.</li>
<li>You can define two colors for the text label. One color will be used for the text which is printed inside the progressbar, the other for text which is outside the progressbar.</li>
<li>You can choose from three different brushes: the TextureBrush (progressbar #6 and #9), the GradientBrush (progressbar #2, #4, #5 and #7) and the HatchBrush (progressbar #4 and #5).</li>
<li>You can define the block size and the gap width (progressbar #2 and #3).</li>
<li>Gridlines can be printed inside the progressbar (progressbar #8). You have control over the alignment (top, middle and bottom) as well as over the heights, widths and spacing.</li>
<li>You can define a horizontal or a vertical progressbar (progressbar #5, #9 and #10 are vertical oriented) and two different directions (progressbar #3 is drawn with a right to left direction).</li>
<li>Label can freely rotate (progressbar #9)</li>
</ul>
<h3>Using the control in your code</h3>
<p>The ExtProgressBar control inherits from the Control class. Using it should be as easy as adding a reference to the ExtControls assembly or adding the source files to your own project. After compiling your project, the ExtProgressBar control should show up in your toolbox.</p>
<h3>The code</h3>
<p>One of the most annoying things of the .NET progressbar is the flickering when the bar is repainted. The solution is simple, and SetStyle is the answer. I won&#8217;t go into details here, since there are a lot of articles out there which can explain the usage and working of the following SetStyle call a lot better then I can.</p>
<p><code>SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);</code></p>
<p>These four ControlStyles allow me to paint the control completely trough my own code, flickerfree and with a transparent background.</p>
<h3>The properties</h3>
<p>When creating a control which can be used from the toolbox and which has a lot of settings, you&#8217;ll going to need the Properties Window. Therefor, I wanted all the properties to make use of that usefull window. Since my control only uses simple types (like integers, floats, strings, structures and enumerations) we can just use some Attributes here. Typing</p>
<p><code>[Description(&quot;The size of the control in pixels&quot;), Editor(&quot;Size&quot;, typeof(UITypeEditor)),  DefaultValue(typeof(Size), &quot;100, 23&quot;)]</code></p>
<p>above a property was enough to let the property show up in the Properties Window. All properties with the above Attributes defined, will show up in the category &quot;Misc&quot;. If that&#8217;s not what you want, add a CategoryAttribute, like this: </p>
<p><code>[Category(&quot;Layout&quot;)]</code></p>
<h3>Drawing the control</h3>
<p>To draw the control, one could choose between two different approaches. You can attach a delegate to the OnPaint handler, or override the OnPaint method from the Control class. The latter is preferred, because calling a function trough a delegate is generally a little bit slower then calling a overridden one.</p>
<p><code>protected override void OnPaint(PaintEventArgs e) { &nbsp;&nbsp;&nbsp;&nbsp;... }</code></p>
<p>In this function, we draw the control in five steps:</p>
<ol>
<li>Draw the background</li>
<li>Draw the progress indicator</li>
<li>Draw the gridlines</li>
<li>Draw the label</li>
<li>Draw the borders</li>
</ol>
<h4>Drawing the background and progress indicator</h4>
<p>Drawing the background can be done in a few different ways. We can override the OnPaintBackground method, or draw the background in the OnPaint functions. In this case, we draw the background in the OnPaint function, as we&#8217;ve specified earlier using the SetStyle call (AllPaintingInWmPaint). Drawing the background itselft is no high tech programming. In fact, creating a brush and filling a rectangle is all there is to it.</p>
<p><code>Brush brush = GetBrush(...); g.FillRectangle(brush, g.VisibleClipBounds); brush.Dispose();</code></p>
<p>The GetBrush function creates a brush based on the arguments given. The arguments are filled by the properties set at design time. The GetBrush function is used to create all brushes in the control. Check the code if you want to see what it does exactly, but it&#8217;s nothing more then a few switches and if statements. We call the <em>Dispose</em> method manually when we don&#8217;t need the brush anymore, because we wan&#8217;t to free the unmanaged GDI resources immediately.  
<a title="ExtProgressBar Demo Project"  href="http://projects.bovendeur.org/downloads/extprogressbar_demo.zip">Download demo project ~ 16 kB</a> 
<a title="ExtProgressBar Solution"  href="http://projects.bovendeur.org/downloads/extprogressbar_src.zip">Download source code (control + demo  project) ~ 19 kB</a></p>
<h3>Thanks to</h3>
<ul>
<li>James T. Johnson for his article 
<a target="_blank" title="Image Rotation in .NET"  href="http://www.codeproject.com/csharp/rotateimage.asp" onclick="javascript:pageTracker._trackPageview('/external/www.codeproject.com/csharp/rotateimage.asp');" >Image Rotation in .NET</a>.</li>
<li>Bob Powell&#8217;s 
<a target="_blank" title="GDI+ FAQ"  href="http://www.bobpowell.net/faqmain.htm" onclick="javascript:pageTracker._trackPageview('/external/www.bobpowell.net/faqmain.htm');" >GDI+ FAQ</a>.</li>
<li>
<a  href="http://www.stevemedley.net" onclick="javascript:pageTracker._trackPageview('/external/www.stevemedley.net');" >Steve Medley</a> for notifyng me of the incorrect version on this website.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://projects.bovendeur.org/2007/07/05/extprogressbar/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.404 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-10 02:18:28 -->
