<?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>Bitmatic &#187; VS2008</title>
	<atom:link href="http://bitmatic.com/tag/vs2008/feed" rel="self" type="application/rss+xml" />
	<link>http://bitmatic.com</link>
	<description>Lean IT-solutions in .NET/C#</description>
	<lastBuildDate>Tue, 11 Jan 2011 09:37:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Fixing a slow scrolling DataGridView</title>
		<link>http://bitmatic.com/c/fixing-a-slow-scrolling-datagridview</link>
		<comments>http://bitmatic.com/c/fixing-a-slow-scrolling-datagridview#comments</comments>
		<pubDate>Sun, 25 Oct 2009 12:14:43 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[controls]]></category>
		<category><![CDATA[DataGridView]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Scroll]]></category>
		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://bitmatic.com/?p=476</guid>
		<description><![CDATA[Whenever your C#/.NET DataGridView reaches a certain size, it tends to get really slow to scroll. Depending on the speed of your computer this may be more or less noticeable. In an application i did for a client this became a real problem due to a combination of lots of DataGridView cells and fairly slow [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever your C#/.NET DataGridView reaches a certain size, it tends to get really slow to scroll. Depending on the speed of your computer this may be more or less noticeable. In an application i did for a client this became a real problem due to a combination of lots of DataGridView cells and fairly slow computers.<br />
Luckily the solution turned out to be simple&#8230;</p>
<h3>Turn on double buffering</h3>
<p>Turning on double buffering seems to solve the problem. Normally double buffering would only help reduce flickering, since painting is being done to an off-screen buffer, but for the DataGridView it also significantly reduces the amount of functions being called internally in the DataGridView &#8211; thus reducing processor load and increasing speed. (statistics gathered with the <a href="http://www.eqatec.com/tools/tracer">Eqatec Tracer</a>)</p>
<h3>My DataGridView doesn&#8217;t have a DoubleBuffered property !?!?</h3>
<p>For some reason Microsoft has decided to hide the DoubleBuffered property from DataGridView. Luckily you can set it anyway with reflection.<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> ExtensionMethods
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> DoubleBuffered(<span class="kwrd">this</span> DataGridView dgv, <span class="kwrd">bool</span> setting)
    {
        Type dgvType = dgv.GetType();
        PropertyInfo pi = dgvType.GetProperty(<span class="str">"DoubleBuffered"</span>,
            BindingFlags.Instance | BindingFlags.NonPublic);
        pi.SetValue(dgv, setting, <span class="kwrd">null</span>);
    }
}</pre>
<p>Just drop the above class into your project somewhere, or add the function to your existing extension methods.<br />
The extension method allows you to set the DoubleBuffered property on your DataGridView in the following manner:<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
dataGridView1.DoubleBuffered(<span class="kwrd">true</span>);</pre>
<p>You now have a smooth scrolling DataGridView <img src='http://bitmatic.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://bitmatic.com/c/fixing-a-slow-scrolling-datagridview/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Using embedded resource files in visual studio 2008</title>
		<link>http://bitmatic.com/c/using-embedded-resource-files-in-visual-studio-2008</link>
		<comments>http://bitmatic.com/c/using-embedded-resource-files-in-visual-studio-2008#comments</comments>
		<pubDate>Sun, 28 Jun 2009 20:37:17 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://bitmatic.com/?p=341</guid>
		<description><![CDATA[Why embed files ? Many of my projects use a lot of secondary files. It can be images, icons, xml-files, text, sound, whatever&#8230;. These files pose a couple of problems for me: They clutter the program folder. The user may accidentally delete or change them. They expose your graphics/sound files to stealing and copying. They [...]]]></description>
			<content:encoded><![CDATA[<h3>Why embed files ?</h3>
<p>Many of my projects use a lot of secondary files. It can be images, icons, xml-files, text, sound, whatever&#8230;. These files pose a couple of problems for me:</p>
<ul>
<li>They clutter the program folder.</li>
<li>The user may accidentally delete or change them.</li>
<li>They expose your graphics/sound files to stealing and copying.</li>
<li>They expose program-sensitive information that a user may try to use to hack/change the behaviour of the program.</li>
</ul>
<p>Luckily there is a fairly easy solution to parts of these problems. Embed the file in the assembly.</p>
<h3>Embedding a file</h3>
<p>The actual embedding of a file in an assembly in Visual Studio 2008 is very easy indeed. You just add the file to the project, and set the build action to &#8220;Embedded Resource&#8221;.<br />
The compiler will then automagically embed the file in the assembly, where it will be accessible during runtime, to use as you wish. Of course this will make your assembly grow, and with many files, it may grow a lot, but this is usually no problem. You can embed any type of file, and you can arrange the files any way you want in project folders and the like.</p>
<h3>Getting the file from the assembly</h3>
<p>Getting the file out of the assembly is almost as easy as getting it in there. It uses functions from the System.Reflection to access the assembly itself, so adding a &#8220;using System.Reflection;&#8221; to your code is advisable.<br />
There are basically two functions worth noting here:</p>
<ul>
<li>GetManifestResourceNames() &#8211; Gets the names of all the embedded resources in the assembly.</li>
<li>GetManifestResourceStream(string name) &#8211; Returns a stream representing the named resource.</li>
</ul>
<p>So getting hold of the first resource in an assembly is as easy as:</p>
<pre class="csharpcode">
Assembly A = Assembly.GetExecutingAssembly();
<span class="kwrd">string</span>[] names = A.GetManifestResourceNames();
Stream S = A.GetManifestResourceStream(names[0]);</pre>
<p>The above example should get the point across. It is very easy to gain access to an embedded resource as you would access any file.<br />
A more practical example, is using an embedded resource file to set the image of a PictureBox control. It could look like this:</p>
<pre class="csharpcode">
Assembly A = Assembly.GetExecutingAssembly();
Stream S = A.GetManifestResourceStream(<span class="str">"MyProject.Images.jakob.gif"</span>);
pictureBox.Image = Image.FromStream(s);</pre>
<p>In the example here, the actual name of the resource is shown. &#8220;MyProject.Images.jakob.gif&#8221; is the name of a resource called &#8220;jakob.gif&#8221; belonging to the project named &#8220;MyProject&#8221;, and placed in a project folder with the name &#8220;Images&#8221;. This is a fairly ease naming convention, that makes all resource names unique and easy to figure out. If you ever have doubts about the name of a resource, just call GetManifestResourceNames(), and it will tell you the names.</p>
<h3>Saving all the ressources in an assembly to disk</h3>
<p>I&#8217;m going to finish by showing you a nice trick, that shows of the functions i outlined above. It is a function that iterates through all the resources in an assembly, and saves them to disk. It handles the files as raw byte arrays, so it should work with any file. I have tested it on gif, zip and pdf files, and it works like a charm.</p>
<pre class="csharpcode">
<span class="kwrd">private</span> <span class="kwrd">void</span> SaveAllResources()
{
  Assembly A = Assembly.GetExecutingAssembly();
  <span class="kwrd">string</span>[] names = A.GetManifestResourceNames();

  <span class="kwrd">foreach</span> (<span class="kwrd">string</span> filename <span class="kwrd">in</span> names)
  {
    Stream S = A.GetManifestResourceStream(filename);
    <span class="kwrd">byte</span>[] rawFile = <span class="kwrd">new</span> <span class="kwrd">byte</span>[S.Length];

    <span class="rem">//Read the data from the assembly</span>
    S.Read(rawFile, 0, (<span class="kwrd">int</span>)S.Length);

    <span class="rem">//Save the data to the hard drive</span>
    <span class="kwrd">using</span> (FileStream fs = <span class="kwrd">new</span> FileStream(filename, FileMode.Create))
    {
      fs.Write(rawFile, 0, (<span class="kwrd">int</span>)S.Length);
    }
  }
}</pre>
<p>Have fun embedding <img src='http://bitmatic.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://bitmatic.com/c/using-embedded-resource-files-in-visual-studio-2008/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

