<?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>Component Factory &#187; .NET</title>
	<atom:link href="http://www.componentfactory.com/blog/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.componentfactory.com/blog</link>
	<description>Windows Forms Controls for .NET Smart Client Applications</description>
	<lastBuildDate>Mon, 05 Sep 2011 10:28:26 +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>Redgate Blunder?</title>
		<link>http://www.componentfactory.com/blog/2011/05/redgate-blunder/</link>
		<comments>http://www.componentfactory.com/blog/2011/05/redgate-blunder/#comments</comments>
		<pubDate>Thu, 12 May 2011 15:00:49 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=696</guid>
		<description><![CDATA[First some background. Unless you are new to .NET development you will have heard of and probably used the excellent .NET Reflector tool that was written some years ago by Lutz Roeder. It takes a .NET assembly and does a good job of decompiling it into C#. It has many more features than just this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>First some background.</strong><br />
Unless you are new to .NET development you will have heard of and probably used the excellent .NET Reflector tool that was written some years ago by <a href="http://www.lutzroeder.com/">Lutz Roeder</a>. It takes a .NET assembly and does a good job of decompiling it into C#. It has many more features than just this but that is the core functionality. I have used it many times to help me understand how the base classes work in WinForms. In August 2008 Lutz sold .NET Reflector to <a href="http://www.red-gate.com/">Red Gate Software</a> who continued to provide a free version but they also developed extra features that became commercial versions.</p>
<p><strong>Show Me The Money</strong></p>
<p>On Feb 2nd 2011 they announced that they would be charging $35 for the tool. When a product has been available for many years for free the market expects it to remain free. Especially when Lutz sold it to Red Gate and the impression people received at the time was that a version of  it would remain forever free.</p>
<p>This has created some backlash from developers, not all developers, but a vocal minority who feel they have been bait and switched. More importantly it created a hole in the market at the free price point. Two commercial companies have jumped into that space with <a href="http://www.telerik.com/products/decompiling.aspx">JustDecompile</a> from Telerik and <a href="http://www.jetbrains.com/decompiler/">dotPeek </a>from JetBrains. Both of these are free. There is also an open source project called <a href="http://wiki.sharpdevelop.net/ILSpy.ashx">ILSpy</a> that is making progress in replicating .NET Reflector functionality.</p>
<p><strong>Back Flip</strong><br />
In response Red Gate have backtracked slightly with the following <a href="http://www.reflector.net/2011/04/why-we-reversed-some-of-our-reflector-decision/">announcement</a>. Basically it says that existing users of .NET Reflector can continue using version 6.8 for free into the future but all new customers will still need to pay. You can see the <a href="http://www.reflector.net/">pricing </a>for new customers here. This whole flip flop has really damaged the reputation of Red Gate.</p>
<p>It has also opened up a free for all where alternative tools will be developed when previously no one considered it worthwhile. I wonder if in a couple of years this will all be forgotten or will Red Gate look back and rue the decisions they made?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2011/05/redgate-blunder/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>VS2010 is working!</title>
		<link>http://www.componentfactory.com/blog/2010/04/vs2010-is-working/</link>
		<comments>http://www.componentfactory.com/blog/2010/04/vs2010-is-working/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 02:37:50 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=642</guid>
		<description><![CDATA[With great relief I managed to work out the problem and as luck would have it I solved the problem just 10 minutes before Microsoft support called me to investigate the bug report. Thanks to Lex Li for pointing me at the support website instead of the connect site for reporting the issue. So what was [...]]]></description>
			<content:encoded><![CDATA[<p>With great relief I managed to work out the problem and as luck would have it I solved the problem just 10 minutes before Microsoft support called me to investigate the bug report. Thanks to Lex Li for pointing me at the support website instead of the connect site for reporting the issue.</p>
<p>So what was the problem? I already had VS2008 installed and had setup the symbol server settings so I could step into and see the source code for the framework Windows Forms code. This has been very handy in the past for tracking down problems by allowing me to see exactly what was happening in the base classes. Reflector is an excellent tool but there is nothing quite like stepping through the real code.</p>
<p>Well it seems that VS2010 was using the already defined settings and this was the cause of the issue. I removed the symbol server settings and it all working perfectly. Put them back again and it takes essentially forever to try and start-up debugging an application. It never occurred to me until I checked that VS2010 would automatically be using the same settings as defined in VS2008. I just assumed you had to set them up manually for each Visual Studio version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2010/04/vs2010-is-working/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>VS2010 still broken</title>
		<link>http://www.componentfactory.com/blog/2010/04/vs2010-still-broken/</link>
		<comments>http://www.componentfactory.com/blog/2010/04/vs2010-still-broken/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 03:05:59 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=638</guid>
		<description><![CDATA[A quick update on the VS2010 problem. As recommend by commenter&#8217;s I have added a bug report on the Microsoft Connect site. If you want to vote the bug upwards it might have a greater chance of being investigated&#8230; (hint hint)&#8230; Microsoft Connect - Bug Report In the meantime I have restored a system image that [...]]]></description>
			<content:encoded><![CDATA[<p>A quick update on the VS2010 problem. As recommend by commenter&#8217;s I have added a bug report on the Microsoft Connect site. If you want to vote the bug upwards it might have a greater chance of being investigated&#8230; (hint hint)&#8230;</p>
<p><a href="https://connect.microsoft.com/VisualStudio/feedback/details/551271/vshost32-clr2-exe-has-stopped-working">Microsoft Connect - Bug Report</a></p>
<p>In the meantime I have restored a system image that I prudently took immediately before the install and so I&#8217;m back again working away although only with VS2008 at the moment. Even-money says the fix from Microsoft will be to wipe the machine and install everything from scratch. Not something I am looking forward to doing as it takes a couple of days to get everything up and running to the point of being able to build Krypton automatically again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2010/04/vs2010-still-broken/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VS2010 is broken</title>
		<link>http://www.componentfactory.com/blog/2010/04/vs2010-is-broken/</link>
		<comments>http://www.componentfactory.com/blog/2010/04/vs2010-is-broken/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 07:14:49 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=634</guid>
		<description><![CDATA[Like a million other .NET developers I rushed to download the Visual Studio 2010 release and installed it on my machine. I hope I&#8217;m the only one that finds it&#8217;s seriously broken when trying to work with a Windows Forms project. All I have to do is the following&#8230; 1, Startup VS2010 2, File -&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Like a million other .NET developers I rushed to download the Visual Studio 2010 release and installed it on my machine. I hope I&#8217;m the only one that finds it&#8217;s seriously broken when trying to work with a Windows Forms project.</p>
<p>All I have to do is the following&#8230;</p>
<p>1, Startup VS2010<br />
2, File -&gt; New -&gt; Project -&gt;<br />
3, Select C# -&gt; Windows Forms Project template<br />
4, Press F5 to compile and run</p>
<p>And then wait forever because after compiling it never runs the application. It makes no difference if I select the .NET Framework 4.0 or 2.0 or any of the others. They fail all the same. It makes no difference if you run as administrator or indeed any other setting I can think of. It&#8217;s just plain broken.</p>
<p>I sometimes also get the following error&#8230;</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/vs2010error.jpg" alt="VS2010 Error" /></p>
<p>Now I find it hard to believe that something so basic would be broken so I must assume it is the setup of my machine helping to expose the problem. I have Windows 7 Professional 64bit with VS2005, VS2008 and now VS2010 all working side by side. Is anyone else using a similar setup and finding it does or does not work with the above steps?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2010/04/vs2010-is-broken/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>No Azure for you</title>
		<link>http://www.componentfactory.com/blog/2010/03/no-azure-for-you/</link>
		<comments>http://www.componentfactory.com/blog/2010/03/no-azure-for-you/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 08:47:09 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=618</guid>
		<description><![CDATA[Over recent months I&#8217;ve spent a few hours playing around with SQL Azure, Silverlight and WCF RIA Services. Nothing serious, just seeing if I could store some data in the cloud within a SQL Azure database and then get that data into a Silverlight application running in a browser. I toyed with the idea of creating [...]]]></description>
			<content:encoded><![CDATA[<p>Over recent months I&#8217;ve spent a few hours playing around with SQL Azure, Silverlight and WCF RIA Services. Nothing serious, just seeing if I could store some data in the cloud within a SQL Azure database and then get that data into a Silverlight application running in a browser. I toyed with the idea of creating the new company website as a Silverlight application and so wanted to play around to see how practical it would be. It would be a good chance to learn more about the technologies as well as making the website unique compared to the competition.</p>
<p>I quickly realised it would take more time than I had available. It also have the disadvantage of expecting all site visitors to either already have or be willing to install Silverlight. I don&#8217;t want to alienate some visitors by having a Silverlight install request as the first thing they see.</p>
<p>Turns out there is another good reason not to bother. Now that Windows Azure and SQL Azure are live it seems Australia has not been invited to the party. If your company is based in the US, UK, Japan, Germany or a good many others then you could sign up. Australia? Thanks but no thanks. You have to wait until some unspecified time in the future before you can use our service.</p>
<p>Good job I dropped the Silverlight idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2010/03/no-azure-for-you/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Control.Visible is broken</title>
		<link>http://www.componentfactory.com/blog/2009/05/controlvisible-is-broken/</link>
		<comments>http://www.componentfactory.com/blog/2009/05/controlvisible-is-broken/#comments</comments>
		<pubDate>Sat, 16 May 2009 09:53:46 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=485</guid>
		<description><![CDATA[I hate the Control.Visible property. It tries to do two things instead of one and so broken. Imagine you have a Panel somewhere in your application and you add a Button onto that Panel. Set the Button.Visible to be False and then back again to True. It works exactly as you would expect by hiding [...]]]></description>
			<content:encoded><![CDATA[<p>I hate the <em>Control.Visible</em> property. It tries to do two things instead of one and so broken.</p>
<p>Imagine you have a <em>Panel</em> somewhere in your application and you add a <em>Button</em> onto that <em>Panel</em>. Set the <em>Button.Visible</em> to be <em>False</em> and then back again to <em>True</em>. It works exactly as you would expect by hiding the control and then displaying it again.</p>
<p>Now move up a level and try setting the <em>Panel.Visible</em> to be <em>False</em> so the whole <em>Panel</em>, including the contained <em>Button</em>, is hidden away. Whilst hidden try asking for the <em>Button.Visible</em> value and you will see it comes back with <em>False</em>! This is bad because it&#8217;s clearly returning a value indicating if the <em>Button</em> is currently visible rather than a value indicating if the <em>Button</em> would like to be visible. There is a big difference between those two semantics.</p>
<p>This problem becomes evident when you want to create your own custom layout panel. Your custom control will need to scan the set of child controls and decide how to arrange them. To make your control behave itself you want to honor the visible setting of child controls. But your stuck because asking a child control for its visible property will not always give the correct answer. If your control performs a layout when it happens to be hidden then all the children will automatically say they want to be hidden as well. Not because they really want to be invisible but purely because at the time the child control was asked the parent chain had a control that was not currently visible.</p>
<p>What we really need is two properties. The <em>Control.Visible</em> should act as an indication of the visible state the control would like to have. So the &#8216;get&#8217; should return the same value as the last &#8216;set&#8217;. Then a new property called <em>Control.CurrentlyVisible </em>that returns if the control is currently visible based on the state of all the parent controls up the chain of controls up to and including the owning <em>Form</em>.</p>
<p>This is something I have had to get around for the <em>KryptonNavigator</em> and <em>KryptonWorkspace</em> controls because they suffer from exactly this issue. They both have child collections of controls and need to honor the visible state of those controls. Luckily I can get around it because they can only have child controls of a type I have defined. So I can easily add the extra properties needed to those defined types. But this would fail if my collection could take any arbitrary control and not just my own types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2009/05/controlvisible-is-broken/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adopt Silverlight?</title>
		<link>http://www.componentfactory.com/blog/2009/03/adopt-silverlight/</link>
		<comments>http://www.componentfactory.com/blog/2009/03/adopt-silverlight/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 06:02:27 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=440</guid>
		<description><![CDATA[Third time&#8217;s a charm? A common belief is it takes three versions before Microsoft really gets a new technology right. Now that Silverlight 3 has been announced at MIX09 it would seem a good time to take a look at this platform. WPF, the big brother of Silverlight, has been around since Vista was released [...]]]></description>
			<content:encoded><![CDATA[<p><span style="FONT-WEIGHT: bold">Third time&#8217;s a charm?</span><br />
A common belief is it takes three versions before Microsoft really gets a new technology right. Now that Silverlight 3 has been announced at MIX09 it would seem a good time to take a look at this platform.</p>
<p>WPF, the big brother of Silverlight, has been around since Vista was released and although a critical success has only slowly gained traction in desktop development. I think this is because WinForms, despite many shortcomings, is good enough for most business focused applications. With few &#8216;must have&#8217; reasons to immediately make the jump, adoption is rising but only slowing.</p>
<p>Silverlight adoption has the potential to happen much faster for two reasons. First is the continuing trend towards richer internet applications. Although you can create nice websites using Ajax, jQuery and HTML it takes great developers pushing the limits to achieve it. Silverlight makes it possible for average developers to do the same but in less time.</p>
<p>The second force is just shear weight of numbers. With about a million .NET developers in the world you are instantly opening up rich internet development for them all. Asking a C#/WinForms developer to learn all about Ajax, jQuery, CSS and so forth is a steep learning curve with no leverage of existing skills. But ask the same developer to keep using C# and much of the same base class library and it becomes much more appealing. Plus once you have mastered Silverlight you can transition that knowledge over to your desktop apps with WPF.</p>
<p>This entire preamble merely explains why I find Silverlight interesting as an area I should start thinking about. I would like to hear bad about others opinions and get a discussion going about this topic.</p>
<p><strong>1, Should Component Factory get involved in Silverlight?</p>
<p>2, What type of controls/components etc would be useful?</strong></p>
<p>I have started a <a href="http://www.componentfactory.com/forums/viewtopic.php?f=4&amp;t=2005#p8301">forum thread</a> for this discussion. This will make it easier to track the full set of responses on an ongoing basis. Thanks.</p>
<p><a href="http://silverlight.net/getstarted/silverlight3/default.aspx">Silverlight 3 Beta Site</a><br />
<a href="http://timheuer.com/blog/archive/2009/03/18/silverlight-3-whats-new-a-guide.aspx">Silverlight Development Links</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2009/03/adopt-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010</title>
		<link>http://www.componentfactory.com/blog/2009/02/visual-studio-2010/</link>
		<comments>http://www.componentfactory.com/blog/2009/02/visual-studio-2010/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 07:07:34 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=427</guid>
		<description><![CDATA[You can see a first glimpse of the new user interface for Visual Studio 2010 on the following Microsoft employee blog. Looks quite nice and makes use of WPF for the editing window. Visual Studio 2010]]></description>
			<content:encoded><![CDATA[<p>You can see a first glimpse of the new user interface for Visual Studio 2010 on the following Microsoft employee blog. Looks quite nice and makes use of WPF for the editing window.</p>
<p><a href="http://blogs.msdn.com/jasonz/archive/2009/02/20/a-new-look-for-visual-studio-2010.aspx">Visual Studio 2010</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2009/02/visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>5 Hidden Features of C#</title>
		<link>http://www.componentfactory.com/blog/2008/10/5-hidden-features-of-c/</link>
		<comments>http://www.componentfactory.com/blog/2008/10/5-hidden-features-of-c/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 08:14:17 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=382</guid>
		<description><![CDATA[When you learn a new language you tend to settle into using it in a particular way. So if you missed a little known feature it is unlikely you will suddenly find it unless someone points it out. Here are 5 of my favorite C# features that you might not already be using. 1 &#8211; ?? [...]]]></description>
			<content:encoded><![CDATA[<p>When you learn a new language you tend to settle into using it in a particular way. So if you missed a little known feature it is unlikely you will suddenly find it unless someone points it out. Here are 5 of my favorite C# features that you might not already be using.</p>
<p><strong>1 &#8211; ?? Operator<br />
</strong>The <span><span class="keyword">??</span></span> operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand. So instead of using code like this&#8230;</p>
<pre><span style="color: #0000ff;">if (reference == null)
   return _defaultInstance;
else
   return reference;</span></pre>
<p>You can just write the following statement instead&#8230;</p>
<pre><span style="color: #0000ff;">return reference ?? _defaultInstance;</span></pre>
<p>Much cleaner and it even works for nullable value types.</p>
<p> </p>
<p><strong>2 - DebuggerStepThrough<br />
</strong>This attribute can be added to a method or property accessor and used to speed up debugging. When debugging and using step-into the debugger will step past the method with this attribute. This is really useful in preventing you stepping in and out of the many one liners in the code. To apply do this&#8230;</p>
<pre><span style="color: #0000ff;"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">string</span><span class="pln"> Name</span></span><span style="color: #0000ff;"><span class="pln"> 
</span><span class="pun">{</span></span><span class="pln">
<span style="color: #0000ff;">   </span></span><span style="color: #0000ff;"><span class="pun">[</span><span class="typ">DebuggerStepThrough</span><span class="pun">]</span></span><span class="pln">
<span style="color: #0000ff;">   </span></span><span style="color: #0000ff;"><span class="kwd">get</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">return</span><span class="pln"> _name</span><span class="pun">;</span><span class="pln"> </span><span class="pun">}</span></span><span class="pln">
<span style="color: #0000ff;">    
   </span></span><span style="color: #0000ff;"><span class="pun">[</span><span class="typ">DebuggerStepThrough</span><span class="pun">]</span></span><span class="pln">
<span style="color: #0000ff;">   </span></span><span style="color: #0000ff;"><span class="kwd">set</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">_name</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> value</span><span class="pun">;</span><span class="pln"> </span><span class="pun">}</span></span><span class="pln">
</span><span class="pun"><span style="color: #0000ff;">}</span></span></pre>
<pre> </pre>
<p><strong>3 &#8211; Automatic Properties<br />
</strong>Sick and tired of adding get/set code for simple properties? This is no longer a problem with the automatic properties added in C# 3.0. Instead of this&#8230;</p>
<pre><span style="color: #0000ff;"><span class="kwd">private</span><span class="pln"> </span><span class="kwd">string</span><span class="pln"> _name</span><span class="pun">;</span></span><span class="pln">
</span><span style="color: #0000ff;"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">string</span><span class="pln"> </span><span class="typ">Name</span></span><span class="pln">
</span><span class="pun"><span style="color: #0000ff;">{</span></span><span class="pln">
<span style="color: #0000ff;">   </span></span><span style="color: #0000ff;"><span class="kwd">get { </span><span class="kwd">return</span><span class="pln"> _name</span><span class="pun">; </span><span class="pun">}</span></span><span class="pln">
</span><span style="color: #0000ff;"><span class="kwd">   set </span><span class="pun">{ </span><span class="pln">_name </span><span class="pun">=</span><span class="pln"> value</span><span class="pun">; </span><span class="pun">}</span></span><span class="pln">
</span><span class="pun"><span style="color: #0000ff;">}</span></span></pre>
<p><span class="pun">&#8230;just do this&#8230;</span></p>
<pre><span class="pun"><span style="color: #0000ff;"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">string</span><span class="pln"> </span><span class="typ">Name</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">get</span><span class="pun">;</span><span class="pln"> </span><span class="kwd">set</span><span class="pun">; }</span></span></span></pre>
<pre> </pre>
<p><strong>4 - Object Initializers</strong></p>
<p>Also introduced in C# 3.0 are object initializers. This allows you to set property values inside the new statement. Without this you either create additional overloaded constructor with the possible set of initial values or you write the long hand like this&#8230;</p>
<pre><span style="color: #0000ff;"><span class="typ">Employee</span><span class="pln"> emp </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Employee</span><span class="pun">();</span><span class="pln">
emp</span><span class="pun">.</span><span class="typ">Name</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="str">"John Smith"</span><span class="pun">;</span><span class="pln">
emp</span><span class="pun">.Age</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> 10</span><span class="pun">;</span></span></pre>
<p><span class="pun">&#8230;but this is clearer&#8230;</span></p>
<pre><span style="color: #0000ff;"><span class="pun"><span class="typ">Employee</span><span class="pln"> emp </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Employee </span><span class="pun">{</span><span class="typ">Name</span><span class="pun">=</span><span class="str">"John Smith"</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Age</span><span class="pun">=</span><span class="typ">10}
</span></span></span></pre>
<pre></pre>
<p><strong>5 - Constant flags</strong></p>
<p>Want to specify a float instead of a double for a constant? Most people know the &#8216;f&#8217; modifier after a constant number informs the compiler to make it a single float value. But did you know the full list of others flags?</p>
<pre class="prettyprint"><code><span style="color: #0000ff;"><span class="pln">100m  (decimal)
100f  (float)
100d  (double)
100u  (uint)
100l  (long)
100ul (ulong)</span></span></code></pre>
<p>Let me know if I have missed one you really like.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/10/5-hidden-features-of-c/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Krypton Icon Pack</title>
		<link>http://www.componentfactory.com/blog/2008/10/krypton-icon-pack/</link>
		<comments>http://www.componentfactory.com/blog/2008/10/krypton-icon-pack/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 09:17:53 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=378</guid>
		<description><![CDATA[If you&#8217;re building an application using the Krypton controls then you need to add a final polish by using a set of professional icons. Otherwise all that hard work creating a nice looking app is going to waste. To help make this process as easy as possible you can now buy a pack of 265 [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re building an application using the Krypton controls then you need to add a final polish by using a set of professional icons. Otherwise all that hard work creating a nice looking app is going to waste.</p>
<p>To help make this process as easy as possible you can now buy a pack of 265 icons. As an introductory offer the price is just $79 during this month. Each icon has&#8230;</p>
<p><strong>Three different sizes</strong></p>
<p><img src="http://www.componentfactory.com/images/IconSizes.png" alt="" /></p>
<p><strong>Three different states</strong></p>
<p><img src="http://www.componentfactory.com/images/IconStates.png" alt="" /> </p>
<p><strong>6 different file formats</strong></p>
<p><strong>- </strong>PNG, GIF<br />
- ICO, PSD<br />
- BMP (24bit &amp; 32bit).</p>
<p>You can see a preview of all the icons <a href="http://www.componentfactory.com/products_iconpack.php">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/10/krypton-icon-pack/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Release inflation</title>
		<link>http://www.componentfactory.com/blog/2008/10/release-inflation/</link>
		<comments>http://www.componentfactory.com/blog/2008/10/release-inflation/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 02:19:11 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=372</guid>
		<description><![CDATA[Is it my imagination or is Microsoft releasing technologies faster and faster than ever before? When I was a young developer using Visual C++ it seemed that you could easily know all the technologies at any one time. All you had to learn was a language, a framework and a library (C++, MFC and STL). Fast forward [...]]]></description>
			<content:encoded><![CDATA[<p>Is it my imagination or is Microsoft releasing technologies faster and faster than ever before? When I was a young developer using Visual C++ it seemed that you could easily know all the technologies at any one time. All you had to learn was a language, a framework and a library (C++, MFC and STL).</p>
<p>Fast forward to today and there would seem to be inflation in the number of product releases from Microsoft. From the release of Vista onwards we have the following client side technologies&#8230;</p>
<p>  <a href="http://msdn.microsoft.com/en-us/netframework/aa663326.aspx">WPF</a>   <a href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx">WCF</a>   <a href="http://msdn.microsoft.com/en-us/netframework/aa663328.aspx">WF</a>   <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx">LINQ</a></p>
<p>Each of these covers a large area that would require many months to really understand well. In fact WPF alone is going to take you a year of full time use before you can say you&#8217;re truly proficient in it. If you want to include the server side then add the following into the mix&#8230;</p>
<p>  <a href="http://msdn.microsoft.com/en-us/library/bb398874.aspx">ASP.NET AJAX</a>  <br />
  <a href="http://weblogs.asp.net/scottgu/archive/2008/10/02/october-2nd-links-asp-net-asp-net-mvc-asp-net-dynamic-data.aspx">ASP.NET MVC</a><br />
  <a href="http://weblogs.asp.net/scottgu/archive/2008/10/02/october-2nd-links-asp-net-asp-net-mvc-asp-net-dynamic-data.aspx">ASP.NET Dynamic Data</a><br />
  <a href="http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx">ADO.NET Entity Framework</a><br />
  <a href="http://www.microsoft.com/SILVERLIGHT/">Silverlight</a></p>
<p>I think I know why this rapid increase has happened and it&#8217;s all the fault of the .NET Framework. When I switched from developing applications with MFC/ATL to WinForms I noticed my productivity increased several fold. Maybe as much as a 5 fold increase in output once I was up to speed with using all the .NET goodness. Now you apply this same productivity increase to all the cubicles at the mothership and you have the above technology tsunami.</p>
<p>When I started as a Windows developer the only real distinction between us was the language that you used (C++ or VB). With the rise of the Internet the community split into server side and client side specialists. It was very hard to master both areas because of the sheer amount of knowledge needed although the better programmers could probably just about manage it.</p>
<p>Now I see the community is splitting again into even smaller groupings. Do you use WinForms or WPF? Do you use classic ASP.NET or the MVC Framework? Over time I expect to see this kind of fracturing into smaller and smaller groups to continue. Or at least that&#8217;s what I was expecting to happen. Maybe Microsoft has seen this trend and decided to try and reverse it. Is the use of XAML with WPF and Silverlight an attempt to unify your client and web developers back into one happy community again? Time will tell.</p>
<p>A worrying trend for Microsoft is that your average programmer is not even bothering to try and learn all the latest goodness. How many developers in your outfit actually use generics beyond List&lt;T&gt;? Generics have been around forever, at least compared to the above technologies, and still most developers are hardly using it. I heard a podcast where an interviewer for a .NET position found that only around 20% of the candidates actually used generics at all. Yikes.</p>
<p>Actually this is not really surprising as the majority of developers spend all day working on business applications that are going to generate revenue. When do you have the time to learn WPF/WCF/LINQ/etc when learning them is almost a full time job in itself? It is all very well for <a href="http://weblogs.asp.net/Scottgu/">Scott Guthrie</a> or <a href="http://www.hanselman.com/blog/">Scott Hanselman</a> to tell the world how great the new stuff is but real developers just don&#8217;t have the schedule to stop and learn for six months.</p>
<p>For me this is the biggest problem that Microsoft is facing. They have some great technologies but the challenge is how to get the bulk of developers, the average developer, to move forward and learn them. I expect the upcoming PDC2008 will release even more new tech but I wonder what they are going to do that makes it easier or more compelling for businesses to move forward and actually use them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/10/release-inflation/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Windows Cloud</title>
		<link>http://www.componentfactory.com/blog/2008/10/windows-cloud/</link>
		<comments>http://www.componentfactory.com/blog/2008/10/windows-cloud/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 09:14:29 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=368</guid>
		<description><![CDATA[Did you realise that Microsoft are releasing a new operating system in just four weeks that is currently being called Windows Cloud? No, me neither. Steve Ballmer made the announcement at a conference in London on Wednesday. Luckily &#8216;Cloud&#8217; is just the project name as it gets a snazzier name at release. It seems that if [...]]]></description>
			<content:encoded><![CDATA[<p>Did you realise that Microsoft are releasing a new operating system in just four weeks that is currently being called Windows Cloud? No, me neither. Steve Ballmer made the <a href="http://news.zdnet.co.uk/internet/0,1000000097,39497208,00.htm">announcement</a> at a conference in London on Wednesday. Luckily &#8216;Cloud&#8217; is just the project name as it gets a snazzier name at release.</p>
<p>It seems that if you are building on .NET then they want to make it real easy to just push a button and have that application deployed into the &#8216;cloud&#8217; so that it just works. Taking away the headache of finding a hosting provider, installing and configuring software such as SQL Server would certainly appeal to many. I suspect that the operating system is really just some extensions on top of Windows Server 2008. Just like Small Business Server is not really a different operating system but just Windows with some packaging for businesses placed on top.</p>
<p><a href="http://news.zdnet.co.uk/software/0,1000000121,39497201,00.htm">Amazon</a> are also extending some love to .NET developers by adding support for Windows Server and SQL Server within their EC2 (Elastic Compute Cloud) service. Currently in private beta testing this addition will help Windows developers that need to scale their web service without needing to handle all the scaling issues themselves. You pay only for the compute time used.</p>
<p>If we look into the future a little way we can image what Microsoft would like to achieve. They want .NET developers working on web applications to be able to sign up for a &#8216;cloud&#8217; account and then just press a button within Visual Studio to have it deployed as a live system. With Microsoft, Amazon, Network Solutions and so on being providers of the actual hardware and providing a scalable system for you. Then you pay only for the amount of CPU/Disk used and need never worry about where the server is located. Add in Hyper-V and it becomes much easy for a provider to give every account their own isolated operating system that can then be moved around to different servers as needed.</p>
<p>Another new technology from Microsoft called Live Mesh is going to be presented at the PDC later this month and may well integrate into this story. It seems that the mothership has well and truely embraced &#8216;cloud computing&#8217;. But whatever you do don&#8217;t use that term with Larry Ellison from Oracle. When someone asked Larry what &#8216;cloud computing&#8217; meant he said&#8230;</p>
<p><em>“The interesting thing about cloud computing is that we’ve redefined cloud computing to include everything that we already do. I can’t think of anything that isn’t cloud computing with all of these announcements. The computer industry is the only industry that is more fashion-driven than women’s fashion. Maybe I’m an idiot, but I have no idea what anyone is talking about. What is it? It’s complete gibberish. It’s insane. When is this idiocy going to stop? </em></p>
<p><em>We’ll make cloud computing announcements. I’m not going to fight this thing. But I don’t understand what we would do differently in the light of cloud computing other than change the wording of some of our ads. That’s my view.”</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/10/windows-cloud/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WPF adoption</title>
		<link>http://www.componentfactory.com/blog/2008/09/wpf-adoption/</link>
		<comments>http://www.componentfactory.com/blog/2008/09/wpf-adoption/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 09:25:41 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=358</guid>
		<description><![CDATA[When WPF was first released I wrote a blog post stating that it would take a little time for it to take off. It has been over two years now and I’ve been proved more right than I expected. I think WPF has great potential and allows some amazing user interfaces to be created. But [...]]]></description>
			<content:encoded><![CDATA[<p>When WPF was first released I wrote a blog post stating that it would take a little time for it to take off. It has been over two years now and I’ve been proved more right than I expected. I think WPF has great potential and allows some amazing user interfaces to be created. But somehow it just hasn&#8217;t taken off.</p>
<p>I expected it to take time because any new platform needs a chance to mature and the associated tooling be created. Even so I expected that by now it would be getting into its stride and starting to overtake WinForms as the client technology of choice. I think there are two reasons why this has not happened.</p>
<p><strong>WPF Tooling</strong><br />
So far this has not reached the level needed to make it easy for average developers to use. Sure, we have Expression Blend and the Visual Studio design time environment but neither is as simple to use as the WinForms design time surface. If you’re not a designer, and most coders never will be, then Blend is really not that easy to use. It&#8217;s easy to create bad designs with Blend but you’re going to need to be a skilled designer to make it really sing for you.</p>
<p>So unless your organization has the resources to employ a designer you&#8217;re stuck with using the standard out of the box look and feel. That standard appearance will not have your customers or boss into begging for WPF applications.</p>
<p>Now this would not be such as issue if there were some great component suites that you could buy and just drop into your application, along with a selection of great themes. The current component suites for WPF are getting better all the time but still at least 1 or 2 years away from providing the depth and range required.</p>
<p><strong>WPF Applications</strong><br />
Our second roadblock to adoption is that we have no good examples of WPF applications in the wild. Yes there are plenty of cool niche apps but I mean really popular apps that are on everyone’s desktop. Something along the lines of Microsoft Word with a WPF front end. Something that gets the mass market asking for the same sophistication from all the applications they use. This would create a demand side pull on software companies.</p>
<p>Of course, the problem here is that you cannot take several million lines of code inside Office and just stick a WPF front end on. This reminds me of an interview I heard from a developer on the Outlook team. It took a team of three developers two years to create the Outlook 2007 navigation control that you see on the left hand side. So we cannot expect the consumer market to get anything from Microsoft in the immediate future that is going to really fire them up.</p>
<p><strong>Supply Side Push</strong><br />
If a demand side pull is unlikely to bring WPF to the masses then the only alternative is for Microsoft to create a supply side push. I think this is the main reasoning behind the recent <a href="http://blogs.zdnet.com/microsoft/?p=1595">announcement</a> that Visual Studio 2010 is to have a new text editor built using WPF. They also stated that Version 11 (Visual Studio 2012?) will have the entire shell rewritten in WPF.</p>
<p>Now you can imagine that a million Visual Studio developers will see the cool and slick WPF environment and decide they want to get in on the act. At this point WPF will be the default choice for developing rich client applications and by then the component vendors will also have some nice offerings.</p>
<p>So my new prediction for WPF uptake is a slow but steady increase over the next four years and a tipping point at around 2012 that sees it become the de facto standard for developing client applications. But if you think differently then let me know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/09/wpf-adoption/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Source Code Analysis</title>
		<link>http://www.componentfactory.com/blog/2008/05/source-code-analysis/</link>
		<comments>http://www.componentfactory.com/blog/2008/05/source-code-analysis/#comments</comments>
		<pubDate>Tue, 27 May 2008 09:13:16 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=311</guid>
		<description><![CDATA[Microsoft Source Code Analysis for C# Microsoft has just released a tool that integrates into Visual Studio and is used to look at your C# source code and report style violations. This is great for any project manager that wants to become style enforcer. The intent is to provide compile time warnings/errors about C# code that violates its [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Microsoft Source Code Analysis for C#</strong></p>
<p>Microsoft has just released a tool that integrates into Visual Studio and is used to look at your C# source code and report style violations. This is great for any project manager that wants to become style enforcer. The intent is to provide compile time warnings/errors about C# code that violates its rules.</p>
<p>For example, you might want to enforce a rule that all source files have a header at the top containing a copyright notice along with the company name. You can configure the utility so that it produces either a warning or an error whenever this rule is violated. The current list of rules that it comes with can be turned on or off depending of which are applicable to you.</p>
<p>Personally I like the idea and I think it would be a great tool to use on a new project. Everyone of the team can sit down at the start and agree a set of style guidelines that can then be automatically enforced. But on existing projects I think it would be almost pointless, as the number of violations is going to be huge and the time needed to prettify your code not really be justifiable.</p>
<p><a href="http://code.msdn.microsoft.com/sourceanalysis/Release/ProjectReleases.aspx?ReleaseId=1047">Download Current Release</a><br />
<a href="http://blogs.msdn.com/sourceanalysis/">Associated Microsoft Blog</a></p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/05/source-code-analysis/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Morning Brew</title>
		<link>http://www.componentfactory.com/blog/2008/01/the-morning-brew/</link>
		<comments>http://www.componentfactory.com/blog/2008/01/the-morning-brew/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 08:44:28 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=287</guid>
		<description><![CDATA[I&#8217;ve been missing the Larkware News web feed since it stopped being produced at the end of 2007. It provided a useful round up of interesting links relating mostly to .NET developers. It was a great time saver. But there seems to be a new kid on the block producing something very similar called The [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been missing the <a href="http://www.larkware.com/">Larkware News</a> web feed since it stopped being produced at the end of 2007. It provided a useful round up of interesting links relating mostly to .NET developers. It was a great time saver. But there seems to be a new kid on the block producing something very similar called <a href="http://blog.cwa.me.uk/">The Morning Brew</a>.</p>
<p>I hope Chris can manage to keep up the current level of detail. Maybe he should try offering advertising spots to help cover the bandwidth and server costs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/01/the-morning-brew/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Framework Source</title>
		<link>http://www.componentfactory.com/blog/2008/01/net-framework-source/</link>
		<comments>http://www.componentfactory.com/blog/2008/01/net-framework-source/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 08:17:51 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=285</guid>
		<description><![CDATA[You can now debug into the .NET Framework code when working with Visual Studio 2008. There have been many times when it would have been very helpful to set breakpoints in the base classes such as Control. Until now I used .NET Reflector to see the base code implementation, but that is hard work to follow. [...]]]></description>
			<content:encoded><![CDATA[<p>You can now debug into the <em>.NET Framework</em> code when working with <em>Visual Studio 2008</em>.</p>
<p>There have been many times when it would have been very helpful to set breakpoints in the base classes such as <em>Control</em>. Until now I used <em>.NET Reflector</em> to see the base code implementation, but that is hard work to follow.</p>
<p>Follow these instructions to get started&#8230;<br />
<a href="http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx">Step-by-Step Guide</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/01/net-framework-source/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Watch the Mole</title>
		<link>http://www.componentfactory.com/blog/2008/01/watch-the-mole/</link>
		<comments>http://www.componentfactory.com/blog/2008/01/watch-the-mole/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 01:14:30 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.componentfactory.com/blog/?p=278</guid>
		<description><![CDATA[If you have not already heard of it then I recommend you check out the useful Visual Studio visualizer called Mole. This is a handy tool that is available when you are in the debugger of you .NET application. It works with WinForms as well as WPF applications. Mole Homepage Mole Silverlight Videos http://karlshifflett.wordpress.com/mole-for-visual-studio/ Mole [...]]]></description>
			<content:encoded><![CDATA[<p>If you have not already heard of it then I recommend you check out the useful <em>Visual Studio</em> visualizer called <em>Mole</em>. This is a handy tool that is available when you are in the debugger of you .NET application. It works with <em>WinForms</em> as well as <em>WPF</em> applications.</p>
<p><strong>Mole Homepage<br />
Mole Silverlight Videos<br />
</strong><a href="http://karlshifflett.wordpress.com/mole-for-visual-studio/">http://karlshifflett.wordpress.com/mole-for-visual-studio/</a></p>
<p><strong>Mole Authors Blog</strong><br />
<a href="http://karlshifflett.wordpress.com/">http://karlshifflett.wordpress.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2008/01/watch-the-mole/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Certified Assemblies</title>
		<link>http://www.componentfactory.com/blog/2007/04/certified-assemblies/</link>
		<comments>http://www.componentfactory.com/blog/2007/04/certified-assemblies/#comments</comments>
		<pubDate>Fri, 20 Apr 2007 01:17:00 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://cfweb.componentfactory.net/blog/?p=203</guid>
		<description><![CDATA[What is the difference between a strong signed assembly and a publisher certified assembly? Strong Signed To strong sign an assembly you need to generate an encryption key and use this key to sign the assembly. The signing process generates a hash of the generated code and attaches this using the key to the end [...]]]></description>
			<content:encoded><![CDATA[<p>What is the difference between a strong signed assembly and a publisher certified assembly?</p>
<p><strong>Strong Signed<br />
</strong>To strong sign an assembly you need to generate an encryption key and use this key to sign the assembly. The signing process generates a hash of the generated code and attaches this using the key to the end of the assembly. Whenever the CLR loads the assembly it notices the signing information and uses it to check that the code generates the same hash code as when it was originally compiled. If the hash code no longer matches then the assembly has been tampered with and so the CLR refuses to load it.</p>
<p>Placing an assembly into the global assembly cache (GAC) requires you strong sign the assembly. This is a reasonable precaution because there might be many different applications that are using the GAC assembly and you want to be sure it has not been modified to inject some <span style="font-size: 11pt; line-height: 115%; font-family: 'Georgia','serif'">malicious </span>code.</p>
<p>However, just signing the assembly is not very secure. Anyone can remove the signing information from an assembly, modify the assembly and then sign it again. They cannot sign it with the same original encryption key because, hopefully, that is safely tucked away at the publishers. But they can generate a new key and use that is sign it with instead.</p>
<p>So the second half of the equation is the reference in the calling assembly. When the calling assembly was compiled it embedded a public token for the signed assembly into its reference information. So now when the application loads it not only knows the name of the assembly it wants to load but also it knows that it should be signed with a particular key.</p>
<p>This prevents the attack just mentioned. If someone takes the <em>System.Windows.Forms</em> assembly in the GAC, injects some dodgy code and then resigns it your application is protected. Your application starts up but the CLR loader says the GAC assembly is not signed with the right key to match the one you expected from compile time. Hey presto the load fails and you know something is wrong.</p>
<p><strong>Publisher Signing<br />
</strong>The internet adds a whole new level of threat to your machine. Any bored developer could write a <span style="font-size: 11pt; line-height: 115%; font-family: 'Georgia','serif'">Trojan </span>horse application and offer it for download from a benign looking website. That free <em>Spyware Remover</em> application actually installs a key logger to grab your bank account details. They have signed all the assemblies in the application so it looks well behaved. But all the signing does is tell you the <span style="font-size: 11pt; line-height: 115%; font-family: 'Georgia','serif'">Trojan </span>horse application is intact and in the original condition intended by the nefarious developer!</p>
<p>This is where the trust based security model comes into play. Whenever you download an application, or installer, from the internet and then try to run it Windows will tell show you a warning. Asking you if you really want to run this software and then present you with information about the publisher of the software. If you trust the publisher then you would let it run, it you don&#8217;t trust the publisher or if there is no publisher details at all then you should not run it.</p>
<p>As a publisher you can get hold of a publisher certificate from one of the big providers such as VeriSign and use that to sign the application/installer. Then the downloader gets shown you publisher details and can be sure it is from a trusted source and has also not been <span style="font-size: 11pt; line-height: 115%; font-family: 'Georgia','serif'">tampered </span>with since it was created. </p>
<p><em>Component Factory</em> has its own certificate from VeriSign and we sign all our installers so you can be sure it is in the original intended state and has not been tampered with.</p>
<p><strong>Publisher Signing Assemblies<br />
</strong>As well as publisher signing your application/installer you should also publisher sign all of the individual assemblies as well. This has a couple of benefits.</p>
<p>First of all the end user can right click any of your assemblies and see that it is signed and examine the certificate details. This should give them a nice <span style="font-size: 11pt; line-height: 115%; font-family: 'Georgia','serif'">cozy </span>feeling and allow your support people to show that it is not your assembly that has been hacked on your end users infected machine.</p>
<p>But the most important benefit is that it allows your assemblies to be used by an application that is undergoing Vista certification. The certification requirements to get the Vista logo require that your application, and crucially all the assemblies that it references, be publisher signed. As a component vendor it is essential that our own assemblies are therefore signed so that applications built by our customers can pass the logo requirements.</p>
<p><strong>Component Factory Assemblies</strong><br />
This requirement only came to light today when a customer needed publisher signed copies of the Krypton 2.5.1 release so they could progress with Vista logo certification. If you also need them just fire off an email to use and we can provide them on demand. All future releases of Krypton will have them signed automatically as part of the build process.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2007/04/certified-assemblies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Digitally Signing Installers</title>
		<link>http://www.componentfactory.com/blog/2007/04/digitally-signing-installers/</link>
		<comments>http://www.componentfactory.com/blog/2007/04/digitally-signing-installers/#comments</comments>
		<pubDate>Wed, 04 Apr 2007 07:21:24 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://cfweb.componentfactory.net/blog/?p=4</guid>
		<description><![CDATA[When you download an installer from the internet you want to know it has not been tampered with. You want to know it really is from the publisher described. As a component vendor I want to sign my own installers so all users of Krypton can have confidence in the downloads. This is especially important [...]]]></description>
			<content:encoded><![CDATA[<p>When you download an installer from the internet you want to know it has not been tampered with. You want to know it really is from the publisher described.</p>
<p>As a component vendor I want to sign my own installers so all users of <i>Krypton</i> can have confidence in the downloads. This is especially important with <i>Vista</i> as it shows the signing information, or lack of, at the slightest opportunity.</p>
<p><b>Software Publishers Credentials</b><br />
In order to sign an installer you a private key (extension .pvk) and a software publishers certificate ( extension .spc). Obviously signing system would not be very secure if just anybody could create their own software publishers credentials with whatever company name they like. So instead you need to get your credentials  from an approved provider that will then perform some background checking. They check you really are the company you say you are and not just impersonating someone at Microsoft! </p>
<p>I used <a href="http://www.verisign.com/products-services/security-services/code-signing/digital-ids-code-signing/index.html">VeriSign</a> to purchase my publisher credentials at a cost of $499.</p>
<p>I would recommend you start the process of getting your credentials before you need them as it can  a few days to work your way through the process. In my case I had to get a legal notary to sign a document proving I was the person I said I was. This is a reasonable precaution when dealing with a small one man company, you might find the process quicker and easier if you work at a large corporation. </p>
<p>So once you have paid your money and proved your identity you end up with two files.<br />
    <i>MyCompany.pvk</i><br />
    <i>MyCompany.spc</i></p>
<p><b>Signing the Installer</b><br />
If like me your are signing several installers and/or signing on a regular basis then you will want to automate it as part of your build process. In this case you want to use the <i>SignTool</i> utility to perform the actual signing of the installer .msi file. But you cannot provide your two files as parameters directly because <i>SignTool</i> only takes a personal information exchange file (extension .pfx) as input. As luck would have it there is a utility called <i>pvk2pfx</i> that takes our two input files and outputs a .pfx file.</p>
<p>So to sign your installer you need to perform the following two commands:-</p>
<p>Pvk2pfx<br />
    -f<br />
    -pi “password”<br />
    -pvk “MyCompany.pvk”<br />
    -spc “MyCompany.spc”<br />
    -pfx “MyCompany.pfx”</p>
<p>Signtool<br />
    sign<br />
    /p “password”<br />
    /f “MyCompany.pfx”<br />
    /d “Product Description”<br />
    /du &#8220;http://www.myCompany.com&#8221;<br />
    /t &#8220;http://timestamp.verisign.com/scripts/timstamp.dll&#8221;<br />
    /v “MyInstaller.msi”</p>
<p>In practice I put these into a batch file and then just pass to the batch file the password, product description and installer filename. All the other parameters will remain constant.</p>
<p>Now when the user downloads and then tries to run the installer you get some publisher information in the warning dialog.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/InstallWarning.jpg"></p>
<p>You can examine the certificate information in more detail by right clicking the installer and looking at the digital signature tab.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/InstallCertificate.jpg"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2007/04/digitally-signing-installers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find .NET Memory Leaks</title>
		<link>http://www.componentfactory.com/blog/2006/07/find-net-memory-leaks/</link>
		<comments>http://www.componentfactory.com/blog/2006/07/find-net-memory-leaks/#comments</comments>
		<pubDate>Mon, 24 Jul 2006 08:30:31 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://cfweb.componentfactory.net/blog/?p=97</guid>
		<description><![CDATA[How do you track down a memory leak in .NET? Well here is a simple and effective technique that should work for you most of the time. Just because you have a garbage collector does not prevent you from having a memory leak. In this context a memory leak is where you are not releasing [...]]]></description>
			<content:encoded><![CDATA[<p>How do you track down a memory leak in .NET? Well here is a simple and effective technique that should work for you most of the time.</p>
<p>Just because you have a garbage collector does not prevent you from having a memory leak. In this context a memory leak is where you are not releasing all references to an object; so that object is never garbage collected.</p>
<p>So how do you work out where that rogue reference is that prevents it from being cleaned up?</p>
<p>Use the following steps inside Visual Studio 2005.</p>
<p><b>Step 1</b><br />
You need to set your managed project to allow unmanaged code debugging. To do this you right click the project and select <i>Properties</i>. The project properties will be shown and from there you select the <i>Debug</i> page of settings. Then ensure the <i>Enable unmanaged code debugging</i> option is ticked. Just like below.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/Mem1.gif"></p>
<p><b>Step 2</b><br />
Run your application in <i>Debug</i> and set a breakpoint at the place where you know the problem will have already occured. Use your application until you hit your breakpoint.</p>
<p><b>Step 3</b><br />
Show the <i>Immediate</i> window so you can begin entering some debugging commands. If the window is not present then use the <i>View -> Other Windows -> Command Window</i> menu option to bring up the <i>Command</i> window. Inside the command window you use the <i>Immed</i> command and then the <i>Immediate</i> window will be displayed.</p>
<p><b>Step 4</b><br />
Use the <b>!load sos</b> command in the <i>Immediate</i> window to load the <i>Son Of Strike</i> debugging extensions that allow us to examine managed memory.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/Mem2.gif"></p>
<p><b>Step 5</b><br />
Use the <b>!dumpheap -stat</b> command. This will then list out all the different types of object that are on the heap. </p>
<p>Each line gives the number of instances of that type, the total amount of memory those instances occupy, the name of the type and a MT address. The MT (Method Table) address is the address of the type and not of any particular instance of the type. </p>
<p>You can see below an abbreviated example of the output.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/Mem3.gif"></p>
<p>You need to search this list for the type of the object that you think should have already been garbage collected and so should not actually be present. </p>
<p>We will use <i>System.Drawing.Color[]</i> as the example type from this point onwards. Looking at the above output you can see it has four instances.</p>
<p><b>Step 6</b><br />
Use the <b>!dumpheap -mt 7ae7bde4</b> command to list out the four individual instances of the type. Obviously you need to substitute the address from the MT column of the type you are actually interested in.</p>
<p>In our debugging session the four instances are listed as.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/Mem4.gif"></p>
<p><b>Step 7</b><br />
Use <b>!dumpobj 013070f8</b> to list out information about the specific object instance we are interested in from step 6. Again, you need to substitute the actual address with the relevant value found in the previous step. Here is the actual output for the <i>Color[]</i> instance.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/Mem5.gif"></p>
<p><b>Step 8</b><br />
Now that we have found the rogue instance we believe should not exist we need to find the reference that points to it. Use <b>!gcroot 013070f8</b> in order to search for all the references to the instance and also display the call stack for each reference.</p>
<p>In our example there is a single reference to the <i>Color[]</i> and the call stack of the object that references it is displayed in the output.</p>
<p>The first object in the stack is the windows form which references the next object down; which itself referencs the one below it and so forth. </p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/Mem6.gif"></p>
<p>In summary, the set of commands are as follows&#8230;</p>
<p>List all types of objects<br />
<b>!dumpheap -stat</b> </p>
<p>List instances of a type<br />
<b>!dumpheap -mt {addr}</b> </p>
<p>Examine an instance<br />
<b>!dumpobj {addr}</b> </p>
<p>Find references to instance<br />
<b>!gcroot {addr}</b></p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2006/07/find-net-memory-leaks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Smart Tags</title>
		<link>http://www.componentfactory.com/blog/2005/10/adding-smart-tags/</link>
		<comments>http://www.componentfactory.com/blog/2005/10/adding-smart-tags/#comments</comments>
		<pubDate>Wed, 19 Oct 2005 08:58:54 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://cfweb.componentfactory.net/blog/?p=167</guid>
		<description><![CDATA[The easiest way to explain the addition of smart tag functionality to a control or component is to walk through a simple example. I have deliberately kept the example as simple as possible in order to make it quick and easy to see what is required from the additional code you need to write. Step [...]]]></description>
			<content:encoded><![CDATA[<p>The easiest way to explain the addition of smart tag functionality to a control or component is to walk through a simple example. I have deliberately kept the example as simple as possible in order to make it quick and easy to see what is required from the additional code you need to write.</p>
<p><b>Step 1 – Create a new UserControl class</b></p>
<p>Create a new project and add a new UserControl class to your project. In our example we will add the smart tag to a UserControl but in practice you could add it to any of your existing controls or components.</p>
<p>Drag a new instance of the control onto your Form and then select it. This will result in something even less exciting than this picture of the selected control on the Form.</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/SmartTag1.jpg"></p>
<p>I customized my control by changing the background color, asking for a border to be drawn and then painting a string in the client area. The full code for the example generated from these steps is available from a link at the end of the article, so there is no need to type in the code from each step.</p>
<p><b>Step 2 &#8211; Add the designer attribute</b></p>
<p>We need to provide a customized designer for the control in order to provide the information the design time environment needs for showing the smart tag. In order to associate a designer class with the control class we add the following attribute to the control class definition.<br />
<code>
<pre>
[Designer(typeof(UserControl1Designer))]
public class UserControl1 : UserControl
</pre>
<p></code></p>
<p><b>Step 3 &#8211; Implement the designer class</b></p>
<p>The default designer associated with a UserControl is called ControlDesigner and so our custom designer class derives from this. Extending the designer involves overriding just a single property of the base class called ActionLists. This is used to return to the caller a collection of lists that are used to populate the smart tag window. </p>
<p>The default implementation from the ControlDesigner returns an empty collection, hence the absence of the smart tag button when you select the control at design time. Our implementation creates an action list and adds it to the list collection. Here is the complete code for the class.<br />
<code>
<pre>
public class UserControl1Designer : ControlDesigner
{
  public override
             DesignerActionListCollection ActionLists
  {
    get
    {
      DesignerActionListCollection actionLists =
          new DesignerActionListCollection();

      actionLists.Add(
          new UserControl1ActionList(this));

      return actionLists;
    }
  }
}
</pre>
<p></code></p>
<p><b>Step 4 &#8211; Implement an action list</b></p>
<p>This is the class that performs the real work. All action lists must derive from the DesignerActionList base class. We provide a constructor that takes a reference to the designer instance and used it to cache a reference to the control instance.<br />
<code>
<pre>
public class UserControl1ActionList
    : DesignerActionList
{
  private UserControl1 _control;

  public UserControl1ActionList(
      UserControl1Designer owner)
    : base(owner.Component)
  {
    _control = (UserControl1)owner.Component;
  }
</pre>
<p></code><br />
Our simple example is going to expose a BackColor entry on the smart tag window that alters the property with the same name on the UserControl1 instance. Whenever you provide a property action you need to implement the property on the action list class itself. Our implementation of the BackColor just calls onto the underlying UserControl1 instance that was cached in the constructor.<br />
<code>
<pre>
  public Color BackColor
  {
    get { return _control.BackColor; }
    set { _control.BackColor = value; }
  }
</pre>
<p></code><br />
Our last task is to override the GetSortedActionItems method. This is the method that returns a collection of items that are required to be displayed on the smart tag window. In our case we need to add just a single entry for the BackColor.<br />
<code>
<pre>
  public override DesignerActionItemCollection
      GetSortedActionItems()
  {
    DesignerActionItemCollection actions =
        new   DesignerActionItemCollection();

    actions.Add(new DesignerActionPropertyItem(
                      "BackColor",
                      "BackColor",
                      "Appearance",
                      "Background color."));

    return actions;
  }
}
</pre>
<p></code></p>
<p><b>Step 5 – Compile and open in design mode</b></p>
<p>Once you have compiled the above code you should be able to select an instance of the UserControl1 control at design time and then access the defined smart tag. You can see it here in it’s full glory!</p>
<p><img src="http://www.componentfactory.com/blog/data/upimages/SmartTag3.jpg" ></p>
<p>You can download the source code for this sample from <a href="http://www.componentfactory.com/imagesBlog/UserControl1.cs">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2005/10/adding-smart-tags/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ColorMatrix Reloaded</title>
		<link>http://www.componentfactory.com/blog/2005/07/colormatrix-reloaded/</link>
		<comments>http://www.componentfactory.com/blog/2005/07/colormatrix-reloaded/#comments</comments>
		<pubDate>Tue, 19 Jul 2005 09:06:15 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://cfweb.componentfactory.net/blog/?p=185</guid>
		<description><![CDATA[The Matrix Connection Despite the headline this blog entry has absolutely nothing to do with the Matrix set of films. In fact it is about using the ColorMatrix capability of the ImageAttributes class for drawing images. Not only does that description not fit into the title but there is no chance you would have read [...]]]></description>
			<content:encoded><![CDATA[<p><b>The Matrix Connection</b></p>
<p>Despite the headline this blog entry has absolutely nothing to do with the <i>Matrix</i> set of films. In fact it is about using the <i>ColorMatrix</i> capability of the <i>ImageAttributes</i> class for drawing images.</p>
<p>Not only does that description not fit into the title but there is no chance you would have read the entry without the <i>Reloaded</i> part of the name. A marketing guy would call this technique a <i>Teaser</i>. The rest of us call this very sneaky. </p>
<p>If I was selling fish fingers, or any other food, then this would be called a breach of the trade descriptions act and the local council would be onto me. In fact they would already have closed me down. Luckily no one cares about accurate descriptions in the software industry and so we will continue without fear.</p>
<p><b>Drawing a Disabled Image</b></p>
<p>I am in the closing stages of writing a <i>Button</i> control and want to make it look good when it was disabled. There are two ways to handle this issue. The easiest solution for me is to get the developer to provide two images, one for when the control is disabled and another for when it is enabled.</p>
<p>Not only is this lazy but it demands extra work from the developer to use my control. The whole point of our library is to make the developers application look good with a minimum of effort from the developer himself. So the alternative solution, and the one I am taking, is to take the enabled image and then draw it in a disabled appearance.</p>
<p>In the past I have used the <i>ControlPaint.DrawImageDisabled</i> method provided by the framework but I am no longer happy with that solution. I want to provide more flexibility in the appearance and so let the developer choose a variety of different ways the image could be manipulated.</p>
<p><b>Enter The ColorMatrix</b></p>
<p>This is where the <i>ColorMatrix</i> comes into play because it can be used to modify the colors of the image when it is being drawn. So now my button control allows the developer to specify an enumeration of different <i>ColorMatrix</i> settings to be applied.</p>
<p>Here is a picture with three buttons. The name of the enumeration value is used as the button text and the image is drawn in the named style.</p>
<p><img src="http://www.componentfactory.com/imagesBlog/Color_2.gif"/></p>
<p>The first is called normal and has no color modification applied. In the second the matrix is used to convert from color to a black and white scale. Last of all the disabled appearance is achieved by using a gray scale but also making the colors 10% brighter than normal. This gives a more subtle look and feel.</p>
<p><b>GrayScale Matrix Code</b><br />
<code><br />
new ColorMatrix(new float[][]{</p>
<p>new float[]{0.3f,0.3f,0.3f,0,0},<br />
new float[]{0.59f,0.59f,0.59f,0,0},<br />
new float[]{0.11f,0.11f,0.11f,0,0},<br />
new float[]{0,0,0,1,0},<br />
new float[]{0,0,0,0,1}</p>
<p>});<br />
</code><br />
The first three lines of the matrix are used to convert the Red, Green and Blue colors of the pixel in that order. The fourth line is used to convert the alpha channel and the fifth line for adding/subtracting values.</p>
<p>So in this example the fourth and fifth lines use a value of 1 to show they are leaving the alpha channel alone and not applying any addition/subtraction.</p>
<p>The values in column 0, 1 and 2 of the first three lines are the same because in order to convert to a grayscale we need to ensure that the RGB values are the same for the R, G and B. Notice that the 0.3, 0.59 and 0.11 values add up to exactly 1.</p>
<p>These three relative factors are used because the eye has better acuity in the green range than in the red and the red is better than the blue. Hence we want to take more account of the green (0.59) than the red (0.3) than the blue (0.11).</p>
<p><b>Color Intensity</b></p>
<p>There is no limit to the color manipulation you can achieve and so I also added some extra enumeration values for making the image lighter or darker in appearance. These might prove useful in many different situations. Here they are in operation.</p>
<p><img src="http://www.componentfactory.com/imagesBlog/Color_0.gif"/></p>
<p><b>Breaking Point</b></p>
<p>As an experiment I tried converting just two of the colors to grayscale and leaving the third alone. In the example below you can see <i>GrayScale R</i> where the blue and green have been gray scaled but the red left alone. Below that are the other two versions for blue and green variations.</p>
<p><img src="http://www.componentfactory.com/imagesBlog/Color_1.gif"/></p>
<p>The reason they are not coming out perfectly is that the three circles are not filled with pure red, pure green and pure blue. Hence the conversion is not achieving the exact effect I was intending. I have decided to leave these enumeration options in the code although they will not be used very often.</p>
<p><b>Pain Points</b></p>
<p>By providing these different effects out of the box the developer has more options in presenting the button image. They might decide to have the button appear gray scaled normally but become full color when the mouse tracks over it. Alternatively they might want to use a darker version of the image normally and only use the normal image on hot tracking. </p>
<p>The important point is the developer provides just a single image and can then apply different effects without needing to create them using a separate package, such as Paint Shop Pro. To use a really stupid management style phrase, we are removing a <i>Pain Point</i> for the developer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2005/07/colormatrix-reloaded/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoSize</title>
		<link>http://www.componentfactory.com/blog/2005/07/autosize/</link>
		<comments>http://www.componentfactory.com/blog/2005/07/autosize/#comments</comments>
		<pubDate>Tue, 12 Jul 2005 09:06:58 +0000</pubDate>
		<dc:creator>Phil Wright</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://cfweb.componentfactory.net/blog/?p=187</guid>
		<description><![CDATA[.NET Framework 2 Version 2 of the .NET Framework is a great improvement for Windows.Forms developers. Each time I investigate a new area I find some cool new feature that makes life so much easier than before. Control.DisplayRect My previous technical entry has already mentioned use of the DisplayRect property as a way of controlling [...]]]></description>
			<content:encoded><![CDATA[<p><b>.NET Framework 2</b></p>
<p>Version 2 of the .NET Framework is a great improvement for <em>Windows.Forms</em> developers. Each time I investigate a new area I find some cool new feature that makes life so much easier than before. </p>
<p><b>Control.DisplayRect</b></p>
<p>My previous technical entry has already mentioned use of the <i>DisplayRect</i> property as a way of controlling the child space available for positioning children. This is a great feature and without this it would be a real pain to achieve the same effect.</p>
<p><b>Control.AutoSize</b></p>
<p>Now I have noticed another great addition that will save developers time. There is a new <i>Control</i> property called <i>AutoSize</i> that does exactly what it says. When defined it will automatically resize the control appropriately.</p>
<p>For instance, if you create a <i>Button</i> control instance then the control will size itself to fit the <i>Text</i> content. Now this might not sound very exciting, but in the past you had a real pain getting a control such as a <i>Button</i> to size properly.</p>
<p>For a start you would have to get the <i>Font</i> used by the <i>Control</i> and then measure the size of the <i>Text</i> for that <i>Font</i>. Then you need to add on a sensible spacing gap around the text and finally add the border allocation. Not rocket science but still a pain to have to write the code.</p>
<p><b>Header and Button</b></p>
<p>Knowing this great new property is available means I want my own controls to provide the same functionality. If a user can take advantage of <i>AutoSize</i> on a standard windows <i>Button</i> then they will, quite reasonably, expect my own controls to provide the same functionality.</p>
<p>As the image from a previous post show, I have completed the simple <i>Header</i> control for the library. I am now into the process of creating a <i>Button</i> control that reuses the same rendering process.</p>
<p>After a little investigation I worked out how to hook into the auto sizing process. It turns out to be really easy and I recommend that anyone else writing a custom control also adds the capability.</p>
<p><b>GetPreferredSize</b></p>
<p>All you need to do is override the virtual method called <i>GetPreferredSize</i> and return from it a <i>Size</i> instance the is the preferred size you would like your control to be. That&#8217;s it. Just override that one method and your done.</p>
<p>This is so simple there is no excuse for not adding it to your own controls.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.componentfactory.com/blog/2005/07/autosize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

