<?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>C# Help &#187; Win Forms</title>
	<atom:link href="http://www.csharphelp.com/category/articles/winforms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csharphelp.com</link>
	<description>C# Tutorial and Guides</description>
	<lastBuildDate>Tue, 07 Feb 2012 01:03:28 +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>Give your Windows Application Flare with Paint and Transparency Keys</title>
		<link>http://www.csharphelp.com/2010/05/give-your-windows-application-some-flare-with-paint-and-transparency-keys/</link>
		<comments>http://www.csharphelp.com/2010/05/give-your-windows-application-some-flare-with-paint-and-transparency-keys/#comments</comments>
		<pubDate>Tue, 25 May 2010 05:25:10 +0000</pubDate>
		<dc:creator>Steve Munsell</dc:creator>
				<category><![CDATA[Win Forms]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com/?p=2310</guid>
		<description><![CDATA[We all know that functional code is the leg that any good program stands on when it comes right down to it however if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can be easily solved by simply using a graphics creation tool such as [...]]]></description>
			<content:encoded><![CDATA[<p>We all know that functional code is the leg that any good program stands on when it comes right down to it however if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can be easily solved by simply using a graphics creation tool such as Paint, Gimp, or Adobe Photoshop and the Transparency key tool found within the C# program.</p>
<p>To ensure you have the correct amount of space for all form objects needed and even room for adding features down the road, design of your new program becomes the key to a successful build. In keeping with that tradition of design we will need to first layout how we would like our form to look at the end of our project. For this example we will be creating a mock MP3 Player. I have decided to make the form appear in the shape of a banner with the display information and buttons in the center.</p>
<p>Here is how I would like my form to look when it is complete:</p>
<p><img class="alignnone size-full wp-image-2312" title="image001" src="http://www.csharphelp.com/wp-content/uploads/2010/05/image001.jpg" alt="" width="412" height="155" /></p>
<p>As you can tell I am not an artist but for the purpose of this article let’s pretend it is the greatest design ever. You can do this step with nothing but a scratch piece of paper and pen just so you have a visual goal to work towards. Next we want to conceptualize a layout on the form to see if it meets your needs.</p>
<p><img class="alignnone size-full wp-image-2313" title="image002" src="http://www.csharphelp.com/wp-content/uploads/2010/05/image002.jpg" alt="" width="412" height="155" /></p>
<p>Once again, despite the artistry it appears to be in line with my concept.</p>
<p>The next step is where we turn idea into reality. From here going forward we will need to use an image creation program. I will use the basic MS PAINT program to create the form mask that we need. In your program of choice re-create the form that you want to see. It is best to put it in the middle of a slightly larger image. Remember to outline where your form items will be located.</p>
<p><img class="alignnone size-full wp-image-2314" title="image003" src="http://www.csharphelp.com/wp-content/uploads/2010/05/image003.jpg" alt="" width="576" height="426" /></p>
<p>Next we want to fill the surrounding area with a solid color. This color should usually be something obnoxious as it will be easier to locate later down the line. In this example I choose lime green. The white area where your objects will be placed should also be colored to your liking at this point.</p>
<p><img class="alignnone size-full wp-image-2315" title="image004" src="http://www.csharphelp.com/wp-content/uploads/2010/05/image004.jpg" alt="" width="576" height="426" /></p>
<p>This final mask image will show our form in the middle area and the surrounding green area as the mask. Save the image to your desktop or an equally accessible location.</p>
<p>Now we will move to the Visual Studio / C# portion of this process. Create a new Windows Application in Visual Studio and add a PictureBox to the form. Next you will want to select the image mask you just created.<br />
Expand the image and form until it fits correctly. At the end your form should look similar to this example:</p>
<p><img class="alignnone size-full wp-image-2316" title="image005" src="http://www.csharphelp.com/wp-content/uploads/2010/05/image005.jpg" alt="" width="576" height="420" /></p>
<p>In the properties box we will be setting the FormBorderStyle property to “None” to eliminate the top blue title bar. This is where our first bit of code comes into play. Because of a lack of the title bar we need to move the form directly. To achieve this effect you will need to add the following:</p>
<p><strong>[At the top]</strong></p>
<p><span class="code-keyword1"><span lang="CS">using</span></span><span lang="CS"> System.Runtime.InteropServices;<span class="code-keyword1"> </span></span></p>
<p><strong>[Above public Form1()]</strong></p>
<pre>
public static extern bool ReleaseCapture();
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
                 int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]</pre>
<p><strong>[In pictureBox1_MouseDown event]</strong></p>
<pre>private void Form1_MouseDown(object sender,
        System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }</pre>
<p>Source: <a rel="nofollow" href="http://www.codeproject.com/KB/cs/csharpmovewindow.aspx">http://www.codeproject.com/KB/cs/csharpmovewindow.aspx</a></p>
<p>You should now be able to move your form without a title bar.</p>
<p>The final step is setting the transparency key. Please note that you need to select Form1 for this and not the picturebox. From the properties box scroll down to TransparencyKey and set it to the same obnoxious color at your pictures background.</p>
<p>Add and code your objects, run the program and there you have it, a sweet looking form ready to impress your end users.</p>
<p><a href="http://64.207.144.115/wp-content/uploads/2010/05/image006.jpg"><img class="alignnone size-full wp-image-2317" title="image006" src="http://www.csharphelp.com/wp-content/uploads/2010/05/image006.jpg" alt="" width="576" height="444" /></a></p>
<p>If you are unhappy with the layout just re-draw another form and try again. The possibilities are endless.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2010/05/give-your-windows-application-some-flare-with-paint-and-transparency-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColorPicker</title>
		<link>http://www.csharphelp.com/2007/08/colorpicker/</link>
		<comments>http://www.csharphelp.com/2007/08/colorpicker/#comments</comments>
		<pubDate>Wed, 22 Aug 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Win Forms]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=643</guid>
		<description><![CDATA[&#160; Download source files &#8211; 207 Kb Download demo project &#8211; 185 Kb Download Dll &#8211; 164 Kb Download demo project src &#8211; 207 Kb Download demo project exe- 186 Kb Introduction One big framework&#39;s handicap is the low number ofvisual controls.Luckly the most usefull are yet present ,but often we find some problem with [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><span class="smallblack">
<li><a href="http://www.csharphelp.com/archives4/files/archive663/ColorPickers_src.zip">Download source files &#8211; 207 Kb</a></li>
<li><a href="http://www.csharphelp.com/archives4/files/archive663/ColorPickers_TEST.zip">Download demo project &#8211; 185 Kb</a></li>
<li><a href="http://www.csharphelp.com/archives4/files/archive663/ColorPickers_DLL.zip">Download Dll &#8211; 164 Kb</a></li>
<li><a href="http://www.csharphelp.com/archives4/files/archive663/ColorPickers_demo_src.zip">Download demo project src &#8211; 207 Kb</a></li>
<li><a href="http://www.csharphelp.com/archives4/files/archive663/ColorPickers_demo_exe.zip">Download demo project exe- 186 Kb</a></li>
<p></span></p>
<p><span class="smallblack"><img src="http://www.csharphelp.com/archives4/files/archive663/ColorPickerControls.jpg" alt="Sample Image - ColorPicker.jpg" height="382" width="614" /></span></p>
<h2><span class="smallblack">Introduction</span></h2>
<p><span class="smallblack">One big framework&#39;s handicap is the low number ofvisual controls.Luckly the most usefull are yet present ,but often we find some problem with the less common control.Some days ago I make a program that translate the colors in thehtml code.In the first I used simply three trackbar to change the red,green and blue.In a second moment I need to put a more quick andintuitive solution,so I build this ColorPicker.This contol allow toselect a color faster than the previos way.Because I haven&#39;t seena similar control in this section ,I decide to post it.<br />In the last update I add a consistent number of controls.AllControls are listed below:<br /></span></p>
<p>&lt;center&gt;<br />
<table border="1" width="60%">
<tbody>
<tr>
<td align="center">ColorPickers (namespace Fuliggine.ColorPickers)</td>
</tr>
<tr>
<td align="left">StableColorPicker</td>
<td align="left">Is a circolar color picker it allow to select a single color.</td>
</tr>
<tr>
<td align="left">SquareColorPicker</td>
<td align="left">Is a control that ,given a base color show and allow to select it&#39;s tones.</td>
</tr>
<tr>
<td align="left">ColorBar</td>
<td align="left">Is a control that show and allow to select all base color derived from rgb except white and black.</td>
</tr>
<tr>
<td align="left">FullColorBar</td>
<td align="left">Is a control that show and allow to select all base color derived from rgb (also white and black).</td>
</tr>
<tr>
<td align="left">ColorViewers (namespace Fuliggine.ColorPickers)</td>
</tr>
<tr>
<td align="left">MonoFrameColor</td>
<td align="left">Is a control with frame that show the selected color.</td>
</tr>
<tr>
<td align="left">DoubleFrameColor</td>
<td align="left">Is a control with two frame that show the two selected colors.</td>
</tr>
<tr>
<td align="left">ColorGradient</td>
<td align="left">Is a control that show all tones of a given color;</td>
</tr>
<tr>
<td align="left">Special Pointers (namespace Fuliggine.ColorPickers)</td>
</tr>
<tr>
<td align="left">HolePointer</td>
<td align="left">Is the pointer that select the color in the controls.</td>
</tr>
</tbody>
</table>
<p>&lt;/center&gt;<br />
<h1><span class="smallblack">The ColorPickers Controls</span></h1>
<p><span class="smallblack">The most part of thoose controls dont need any word,almost i think.For CodeBar and full code bar I divide the width in some section to allowsall the possibles combination of R,G,B.After that I find the step of color donein every pixel an draw the control line by line&#8230;</span></p>
<p><span class="smallestblack"><span class="cpp-keyword"><span class="smallblack">protected</span></span><span class="smallblack"> override <span class="cpp-keyword">void</span> OnPaint(PaintEventArgs e)<br />{ <span class="cpp-keyword">int</span> R=<span class="cpp-literal">255</span>;<br /> <span class="cpp-keyword">int</span> G=<span class="cpp-literal">0</span>;<br /> <span class="cpp-keyword">int</span> B=<span class="cpp-literal">0</span>;<br /> <span class="cpp-comment">//orizzontal&#8230;</span></p>
<p> <span class="cpp-keyword">int</span> colorstep=<span class="cpp-literal">255</span>/ ( <span class="cpp-keyword">this</span>.Width/<span class="cpp-literal">6</span> );<br /> <span class="cpp-keyword">int</span> i=<span class="cpp-literal">0</span>;<br /> <span class="cpp-comment">//the color step x pixel</span></p>
<p> <span class="cpp-keyword">for</span>(B=<span class="cpp-literal">0</span>;B&lt;<span class="cpp-literal">256</span>;B+=colorstep ,i++)<br /> {<br /> e.Graphics.DrawLine(<span class="cpp-keyword">new</span> Pen(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(R,G,B)),<span class="cpp-literal">1</span>),i,<span class="cpp-literal">0</span>,i,<span class="cpp-keyword">this</span>.Height);</p>
<p> }<br /> B=<span class="cpp-literal">255</span>;<br /> <span class="cpp-keyword">for</span>(R=<span class="cpp-literal">255</span>;R&gt;<span class="cpp-literal">0</span>;R-=colorstep,i++)<br /> {</p>
<p> e.Graphics.DrawLine(<span class="cpp-keyword">new</span> Pen(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(R,G,B)),<span class="cpp-literal">1</span>),i,<span class="cpp-literal">0</span>,i,<span class="cpp-keyword">this</span>.Height);</p>
<p> }<br /> R=<span class="cpp-literal">0</span>;<br /> <span class="cpp-keyword">for</span>(G=<span class="cpp-literal">0</span>;G&lt;<span class="cpp-literal">256</span>;G+=colorstep,i++)<br /> {<br /> e.Graphics.DrawLine(<span class="cpp-keyword">new</span> Pen(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(R,G,B)),<span class="cpp-literal">1</span>),i,<span class="cpp-literal">0</span>,i,<span class="cpp-keyword">this</span>.Height);</p>
<p> }<br /> G=<span class="cpp-literal">255</span>;</p>
<p> <span class="cpp-keyword">for</span>(B=<span class="cpp-literal">255</span>;B&gt;<span class="cpp-literal">0</span>;B-=colorstep,i++)<br /> { <br /> e.Graphics.DrawLine(<span class="cpp-keyword">new</span> Pen(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(R,G,B)),<span class="cpp-literal">1</span>),i,<span class="cpp-literal">0</span>,i,<span class="cpp-keyword">this</span>.Height);</p>
<p> }</p>
<p> B=<span class="cpp-literal">0</span>;</p>
<p> <span class="cpp-keyword">for</span>(R=<span class="cpp-literal">0</span>;R&lt;<span class="cpp-literal">256</span>;R+=colorstep,i++)<br /> {<br /> e.Graphics.DrawLine(<span class="cpp-keyword">new</span> Pen(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(R,G,B)),<span class="cpp-literal">1</span>),i,<span class="cpp-literal">0</span>,i,<span class="cpp-keyword">this</span>.Height);</p>
<p> }<br /> R=<span class="cpp-literal">255</span>;<br /> B=<span class="cpp-literal">0</span>;<br /> <span class="cpp-keyword">for</span>(G=<span class="cpp-literal">255</span>;G&gt;<span class="cpp-literal">0</span>;G-=colorstep,i++)<br /> {<br /> e.Graphics.DrawLine(<span class="cpp-keyword">new</span> Pen(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(R,G,B)),<span class="cpp-literal">1</span>),i,<span class="cpp-literal">0</span>,i,<span class="cpp-keyword">this</span>.Height);</p>
<p> }</p>
<p>}</p>
<p></span>
<p><span class="smallblack">A similar way is used also in the Color Gradient and SquareColorPicker,but there only the tones of the color are shown.</span></p>
<p><span class="smallestblack"><span class="cpp-keyword"><span class="smallblack">protected</span></span><span class="smallblack"> override <span class="cpp-keyword">void</span> OnPaint(PaintEventArgs e)<br />{<span class="cpp-keyword">int</span> ScaleY=<span class="cpp-literal">255</span>/<span class="cpp-keyword">this</span>.Height;</p>
<p> <span class="cpp-keyword">for</span> ( <span class="cpp-keyword">int</span> y = <span class="cpp-literal">0</span> ; y&lt;<span class="cpp-keyword">this</span>.Height;y++)<br /> {<br /> <span class="cpp-keyword">int</span> r=pColor.R-(y*ScaleY);<br /> <span class="cpp-keyword">if</span>(r&lt;<span class="cpp-literal">0</span>)<br /> {<br /> r=<span class="cpp-literal">0</span>;<br /> }</p>
<p> <span class="cpp-keyword">int</span> g=pColor.G-(y*ScaleY);<br /> <span class="cpp-keyword">if</span></p>
<p>(g&lt;<s<br />
pan class="cpp-literal">0</span>)<br /> {<br /> g=<span class="cpp-literal">0</span>;<br /> }</p>
<p> <span class="cpp-keyword">int</span> b=pColor.B-(y*ScaleY);<br /> <span class="cpp-keyword">if</span>(b&lt;<span class="cpp-literal">0</span>)<br /> {<br /> b=<span class="cpp-literal">0</span>;<br /> }<br /> e.Graphics.DrawLine(<span class="cpp-keyword">new</span> Pen(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(r,g,b)),<span class="cpp-literal">1</span>),<span class="cpp-literal">0</span>,y,<span class="cpp-keyword">this</span>.Width,y);<br /> }<br /> }</p>
<p></span>
<p><span class="smallblack">The Mono and Double Fame Color are realized by simple panels .The Hole pointer is a simple control that bring itself in the aprent bounds when them mouse brag it.Basing on its position controls decide what&#39;s the selected color.</span></p>
<h2><span class="smallblack">The Color Picker Application</span></h2>
<p><span class="smallblack">The demo is that I find a nice application,tin and simple but usefull forwho always use the HTML language.That application show a way to use the StableColorPicker.</span></p>
<p><span class="smallblack"><img src="http://www.csharphelp.com/archives4/files/archive663/ColorPicker.jpg" alt="Sample Image - ColorPicker.jpg" height="345" width="585" /></span></p>
<h2><span class="smallblack">How to Know the RGB color</span></h2>
<p><span class="smallblack">I have decided to do a round rainbow.The main problem isthat in a RGB sistem we have 3 variables and in the plainthere are only two.So I decide to take the x value as Red,Y value as Green and the distance from center as Blue.The circle is inscripted in a square of 255 pixel for each side.The distance from the center are calculated with the Pitagora&#39;s Theorema and resized to fit in the range 0-255.So at every point are associed one tern of value beethwin 0 and 255.</span></p>
<h2><span class="smallblack">How to paint the circle</span></h2>
<p><span class="smallblack">To paint the circle,I have two Ways:the first one is to paint all the pointon the ray ,for each angle;the second one is to paint every point in a circle each circle .This two different way can be selected by the user .This piece of code isshown here:</span></p>
<p><span class="smallestblack"><span class="smallblack"> <span class="cpp-keyword">protected</span> override <span class="cpp-keyword">void</span> OnPaint(PaintEventArgs e)<br />{<br /><span class="cpp-comment">//set some usefull var</span></p>
<p><span class="cpp-keyword">int</span> offsett= <span class="cpp-literal">1</span>;<br /><span class="cpp-keyword">int</span> width=<span class="cpp-keyword">this</span>.ClientRectangle.Width-<span class="cpp-literal">2</span>;<br /><span class="cpp-keyword">int</span> height=<span class="cpp-keyword">this</span>.ClientRectangle.Height-<span class="cpp-literal">2</span>;<br /><span class="cpp-keyword">int</span> rx= width/<span class="cpp-literal">2</span>;<br /><span class="cpp-keyword">int</span> x=<span class="cpp-literal">10</span>;<br /><span class="cpp-keyword">int</span> y=<span class="cpp-literal">10</span>;<br /><span class="cpp-keyword">int</span> cx=offsett+rx;<br /><span class="cpp-keyword">double</span> teta=<span class="cpp-literal">0</span> ;<br /><span class="cpp-comment">//refresh the background</span></p>
<p>e .Graphics.FillRectangle(<span class="cpp-keyword">new</span> SolidBrush(<span class="cpp-keyword">this</span>.BackColor),<span class="cpp-keyword">this</span>.ClientRectangle);</p>
<p> <span class="cpp-comment">//The core of painting</span><br /> <span class="cpp-keyword">if</span> ( AnimationRadial==<span class="cpp-keyword">true</span>)<br /> {<br /> <span class="cpp-keyword">for</span> ( teta = <span class="cpp-literal">0</span> ; teta &lt;<span class="cpp-literal">2</span>*Math.PI; teta=teta + <span class="cpp-literal">0.003</span>)<br /> {<span class="cpp-keyword">for</span> ( <span class="cpp-keyword">double</span> ray = <span class="cpp-literal">0</span> ; ray&lt;rx ;ray= ray+<span class="cpp-literal">1</span>)<br /> {</p>
<p> x= cx+ Convert.ToInt32(ray* Math.Cos(teta));<br /> y= cx &#8211; Convert.ToInt32(ray* Math.Sin(teta));<br /> Rectangle rect= <span class="cpp-keyword">new</span> Rectangle(x,y,<span class="cpp-literal">1</span>,<span class="cpp-literal">1</span>);</p>
<p> e.Graphics.FillRectangle(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(x,y,(<span class="cpp-keyword">int</span>)(ray/rx*<span class="cpp-literal">255</span>))),rect);</p>
<p> }}}<br /> <span class="cpp-keyword">else</span></p>
<p> {<br /> <span class="cpp-keyword">for</span> ( <span class="cpp-keyword">double</span> ray = <span class="cpp-literal">0</span> ; ray&lt;rx ;ray= ray+<span class="cpp-literal">1</span>)<br /> {<br /> <span class="cpp-keyword">for</span> ( teta = <span class="cpp-literal">0</span> ; teta &lt;<span class="cpp-literal">2</span>*Math.PI; teta=teta + <span class="cpp-literal">0.003</span>)<br /> { <br /> x= cx+ Convert.ToInt32(ray* Math.Cos(teta));<br /> y= cx &#8211; Convert.ToInt32(ray* Math.Sin(teta));<br /> Rectangle rect= <span class="cpp-keyword">new</span> Rectangle(x,y,<span class="cpp-literal">1</span>,<span class="cpp-literal">1</span>);<br /> e.Graphics.FillRectangle(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(x,y,(<span class="cpp-keyword">int</span>)(ray/rx*<span class="cpp-literal">255</span>))),rect);<br /> }}}}<span class="cpp-keyword">protected</span> override <span class="cpp-keyword">void</span> OnPaint(PaintEventArgs e)<br /> {<br /> <span class="cpp-comment">//set some usefull var</span></p>
<p> <span class="cpp-keyword">int</span> offsett= <span class="cpp-literal">1</span>;<br /> <span class="cpp-keyword">int</span> width=<span class="cpp-keyword">this</span>.ClientRectangle.Width-<span class="cpp-literal">2</span>;<br /> <span class="cpp-keyword">int</span> height=<span class="cpp-keyword">this</span>.ClientRectangle.Height-<span class="cpp-literal">2</span>;<br /> <span class="cpp-keyword">int</span> rx= width/<span class="cpp-literal">2</span>;<br /> <span class="cpp-keyword">int</span> x=<span class="cpp-literal">10</span>;<br /> <span class="cpp-keyword">int</span> y=<span class="cpp-literal">10</span>;<br /> <span class="cpp-keyword">int</span> cx=offsett+rx;<br /> <span class="cpp-keyword">double</span> teta=<span class="cpp-literal">0</span> ;<br /> <span class="cpp-comment">//refresh the background</span></p>
<p> e .Graphics.FillRectangle(<span class="cpp-keyword">new</span> SolidBrush(<span class="cpp-keyword">this</span>.BackColor),<span class="cpp-keyword">this</span>.ClientRectangle);</p>
<p> <span class="cpp-comment">//The core of painting</span><br /> <span class="cpp-keyword">if</span> ( AnimationRadial==<span class="cpp-keyword">true</span>)<br /> {<br /> <span class="cpp-keyword">for</span> ( teta = <span class="cpp-literal">0</span> ; teta &lt;<span class="cpp-literal">2</span>*Math.PI; teta=teta + <span class="cpp-literal">0.003</span>)<br /> {<span class="cpp-keyword">for</span> ( <span class="cpp-keyword">double</span> ray = <span class="cpp-literal">0</span> ; ray&lt;rx ;ray= ray+<span class="cpp-literal">1</span>)<br /> {</p>
<p> x= cx+ Convert.ToInt32(ray* Math.Cos(teta));<br /> y= cx &#8211; Convert.ToInt32(ray* Math.Sin(teta));<br /> Rectangle rect= <span class="cpp-keyword">new</span> Rectangle(x,y,<span class="cpp-literal">1</span>,<span class="cpp-literal">1</span>);</p>
<p> e.Graphics.FillRectangle(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(x,y,(<span class="cpp-keyword">int</span>)(ray/rx*<span class="cpp-literal">255</span>))),rect);</p>
<p> }}}<br /> <span class="cpp-keyword">else</span></p>
<p> {<br /> <span class="cpp-keyword">for</span> ( <span class="cpp-keyword">double</span> ray = <span class="cpp-literal">0</span> ; ray&lt;rx ;ray= ray+<span class="cpp-literal">1</span>)<br /> {<br /> <span class="cpp-keyword">for</span> ( teta = <span class="cpp-literal">0</span> ; teta &lt;<span class="cpp-literal">2</span>*Math.PI; teta=teta + <span class="cpp-literal">0.003</span>)<br /> { <br />
x= cx+ Convert.ToInt32(ray* Math.Cos(teta));<br /> y= cx &#8211; Convert.ToInt32(ray* Math.Sin(teta));<br /> Rectangle rect= <span class="cpp-keyword">new</span> Rectangle(x,y,<span class="cpp-literal">1</span>,<span class="cpp-literal">1</span>);<br /> e.Graphics.FillRectangle(<span class="cpp-keyword">new</span> SolidBrush(Color.FromArgb(x,y,(<span class="cpp-keyword">int</span>)(ray/rx*<span class="cpp-literal">255</span>))),rect);<br /> }}}}</p>
<p></span><br />
<h2><span class="smallblack">How to select a color</span></h2>
<p><span class="smallblack">To select a color I made a special class that can be moved by the user.Every Color Picher has one of this and the cpntol return the color under it.</span></p>
<h2><span class="smallblack">Problems</span></h2>
<p><span class="smallblack">A big problem is the flikkerous repainting .I resolve taking the screenshoot of this control,and putting it on a new control derived from paintbox.This isn&#39;t an elegant solution but works&#8230;Icall this new control StableColorPicker</span></p>
<h2><span class="smallblack">Classes</span></h2>
<p><span class="smallblack">In this relase there are the first version of the control(ColorPicker) who work fine,but isn&#39;t very stable,and the second stable version(StableColorPicker).</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/08/colorpicker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# DataGrid combobox Simple Sample</title>
		<link>http://www.csharphelp.com/2007/07/c-datagrid-combobox-simple-sample/</link>
		<comments>http://www.csharphelp.com/2007/07/c-datagrid-combobox-simple-sample/#comments</comments>
		<pubDate>Tue, 24 Jul 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Win Forms]]></category>
		<category><![CDATA[datagrid]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=614</guid>
		<description><![CDATA[Summary This article explains how to add the Combobox DataGrid Column Style into a DataGrid on your .NET Windows form. The sample introduces how to add the Combobox DataGrid Column Style into a DataGrid on your .NET Windows form.The main idea of the sample is to provide you with a suggestion how to update values [...]]]></description>
			<content:encoded><![CDATA[<p><span class="smallblack">Summary </span></p>
<p><span class="smallblack">This article explains how to add the Combobox DataGrid Column Style into a DataGrid on your .NET Windows form. </span></p>
<p><span class="smallblack">The sample introduces how to add the Combobox DataGrid Column Style into a DataGrid on your .NET Windows form.The main idea of the sample is to provide you with a suggestion how to update values in other datagrid cells at a row when the current combobox cell has been updated. For this case when we need to update corresponding cells we are using the DataGrid ComboBoxColumn Leave event. When the user will leave changed combobox cell the event will have effect. In this example project when you change a value in Country column a suitable Capital name will be populated into Capital column and vise versa.</span></p>
<p><span class="smallblack">This combobox column style is not just a dropdown combobox, which appears when a datagrid cell becomes the current cell. The combobox DataGridColumnStyle automatically fills the text at the cursor with the value of its dropdown values list. As characters are typed, the component finds the closest matching item from the list and fills in the remaining characters.</span></p>
<p><span class="smallblack">The Simple Sample describes the Datagrid Combobox basic techniques only. To find out other attractive Datagrid Combobox Column?s features please learn our Datagrid Columns sample projects. Also the code example gives hints how to deal with a database when you need update a set of records in the .NET datagrid interface and store the updates back into datasource database.</span></p>
<p><span class="smallestblack"><span class="smallblack">// Set column styles<br />// Define comboCountry variable as a ComboBoxColumn column style <br />object of DataGridComboBoxColumn class<br />internal DataGridComboBoxColumn comboCountry;<br />// Define comboCapital variable as a ComboBoxColumn column style <br />object of DataGridComboBoxColumn class<br />internal DataGridComboBoxColumn comboCapital;</p>
<p>&#8230;&#8230;&#8230;..</p>
<p>// Set column styles<br />// Set datagrid ComboBox ColumnStyle for Country field comboCountry = (DataGridComboBoxColumn) new <br />DataGridComboBoxColumn(ref <br />Dictionary, 0, 0, true, false, false, <br />DataGridComboBoxColumn.DisplayModes.ShowDisplayMember, 0); comboCountry.Leave += new <br />DataGridComboBoxColumn.LeaveEventHandler<br />(this.comboCountry_Leave); TblStyle.GridColumnStyles.Add(comboCountry);<br />TblStyle.GridColumnStyles[0].MappingName = &quot;Country&quot;; TblStyle.GridColumnStyles[0].HeaderText = &quot;Country&quot;; <br />TblStyle.GridColumnStyles[0].Width = 165; TblStyle.GridColumnStyles[0].NullText = string.Empty;</p>
<p>// Set datagrid ComboBox ColumnStyle for Capital field comboCapital = (DataGridComboBoxColumn) new <br />DataGridComboBoxColumn(ref Dictionary, 1, 1, true, false, false, <br />DataGridComboBoxColumn.DisplayModes.ShowDisplayMember, 0); comboCapital.Leave += new <br />DataGridComboBoxColumn.LeaveEventHandler(this.comboCapital_Leave); TblStyle.GridColumnStyles.Add(comboCapital);<br />TblStyle.GridColumnStyles[1].MappingName = &quot;Capital&quot;; TblStyle.GridColumnStyles[1].HeaderText = &quot;Capital&quot;; <br />TblStyle.GridColumnStyles[1].Width = 165; TblStyle.GridColumnStyles[1].NullText = string.Empty;</p>
<p>&#8230;&#8230;&#8230;..</p>
<p>// &quot;Country&quot; datagrid cell has been left. Update <br />corresponding &quot;Capital&quot; cell value in the current datagrid row private void comboCountry_Leave(object sender, <br />System.EventArgs e) { System.Data.DataRow[] Capital = Dictionary.Select(&quot;Country=&#39;&quot; + <br />comboCountry.combo.Text + &quot;&#39;&quot;); DataGrid1[DataGrid1.CurrentRowIndex, 1] = Capital[0][1]; }</p>
<p>// &quot;Capital&quot; datagrid cell has been left. Update <br />corresponding &quot;Country&quot; cell value in the current datagrid row private void comboCapital_Leave(object sender, <br />System.EventArgs e) { System.Data.DataRow[] Country = Dictionary.Select(&quot;Capital=&#39;&quot; + <br />comboCapital.combo.Text + &quot;&#39;&quot;); DataGrid1[DataGrid1.CurrentRowIndex, 0] = Country[0][0];<br /></span>
<p><span class="smallblack">Learn more about DataGridColumns assembly </span></p>
<p><span class="smallblack">The assembly online documentation: http://www.rustemsoft.com/DataGridColumnsDoc/ <br />Russ Sabitov<br />RustemSoft.com</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/07/c-datagrid-combobox-simple-sample/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Color ListBox</title>
		<link>http://www.csharphelp.com/2007/07/net-color-listbox/</link>
		<comments>http://www.csharphelp.com/2007/07/net-color-listbox/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Win Forms]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=609</guid>
		<description><![CDATA[Yet another color list box? There are many articles about coloring the of ListBox control and code samples.&#160;Well, the difference between this article and the rest is that all those articles and the code supplied with them are just demos. Judge for yourself : The horizontal scrollbar disappeared. Only fixed length strings smaller than the [...]]]></description>
			<content:encoded><![CDATA[<p style="font-family:Tahoma;" align="left"><span class="smallblack"><span style="font-family:Times New Roman;">Yet another color list box? There are many articles about coloring the of ListBox control and code samples.&nbsp;Well, the difference between this article and the rest is that all those articles and the code supplied with them are just demos. Judge for yourself : </span> </span></p>
<p><span class="smallblack"> </span></p>
<ul><span class="smallblack">
<li>
<div align="left">The horizontal scrollbar disappeared. Only fixed length strings smaller than the control width can be displayed. What if the control resized?</div>
</li>
<li>
<div align="left">If you tried to use a mouse wheel, you may have noticed that the selected item moves up and down erratically when the scroll wheel is moved. </div>
</li>
<li>
<div align="left">The overridable methods OnPaint() OnPaintBackGround() do not work at all. Simply they are not hooked to the events. Background is painted only via Windows messages. </div>
</li>
<p></span></ul>
<p><span class="smallblack"> </span></p>
<p style="font-family:Tahoma;" align="left"><span class="smallblack"><span style="font-family:Times New Roman;">The sad conclusion is that as the commercial quality controls they are entirely useless. <br /> .Net ListBox control itself works fine, however as a base class for further derivation it is fundamentally flawed. The root of evil is in the Windows API ListBox.<br /> .Net ListBox is just a wrapper for this control. What is the solution?&nbsp; We can write the control from the scratch or to try to use the existing control and try to work around the problems. Basically this article is the manual how to overcome these problems. </span> </span></p>
<p><span class="smallblack"> </span></p>
<h3 align="center"><span class="smallblack"><img src="http://members.iinet.net/%7Eletchik/DotNetRemoting/Articles/ListBox.gif" alt="" /> </span></h3>
<p><span class="smallblack"> </span></p>
<h3 align="center"><span class="smallblack">The Code</span></h3>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack">The control is derived from UserControl. It has a ListBox and a Horizontal scrollbar as members.<br /> For making it&nbsp;<span style="color:#0033ff;">Ownerdrawn</span> we need a method for drawing the item. Prior to that the DrawMode of the original control has to be set to <span style="color:#3300ff;">DrawMode.OwnerDrawVariable</span>. This will disable the original drawing of the item and also the method <span style="color:#0000ff;"> MeasureItem()</span> will be activated.<br /> The code of DrawItem is below. Apart from a couple of lines it is more or less straightforward. </span></p>
<p><span class="smallblack"> </span></p>
<p><span style="border:thin solid gray;background-color:#ffcc66;"><span class="smallblack"><span style="color:#0000ff;">protected void</span> DrawListBoxItem(Graphics g, Rectangle bounds, <span style="color:#3300ff;">int</span> Index, <span style="color:#0000ff;">bool</span> selected)<br />{<br /> <span style="color:#0000ff;">if </span>(Index == -1)<br /> <span style="color:#0000ff;">return</span>;</p>
<p> <span style="color:#0000ff;">if </span>(bounds.Top &lt; 0)<br /> <span style="color:#0000ff;">return</span>;</p>
<p> <span style="color:#0000ff;">if </span>(bounds.Bottom &gt; (listBox.Bottom + listBox.ItemHeight))<br /> <span style="color:#0000ff;">return</span>;</p>
<p> Graphics gr = <span style="color:#0000ff;">null</span>;</p>
<p> <span style="color:#0000ff;">if </span>(UseDoubleBuffering)<br /> {<br /> gr = DoubleBuff.BuffGraph;<br /> }<br /> <span style="color:#3300ff;">else</span><br /> {<br /> gr = g;<br /> }</p>
<p> <span style="color:#0000ff;">int </span>IconIndex;<br /> Color TextColor;<br /> <span style="color:#0000ff;">string </span>Text = GetObjString(Index, <span style="color:#0000ff;">out </span>IconIndex, <span style="color:#0000ff;">out </span>TextColor);</p>
<p> Image img = <span style="color:#0000ff;">null</span>;</p>
<p> <span style="color:#0000ff;">if </span>(selected)<br /> {<br /> <span style="color:#0000ff;">if </span>(listBox.Focused)<br /> {<br /> <span style="color:#0000ff;">using</span>(Brush b = <span style="color:#0000ff;">new</span> SolidBrush(_HighLightColor))<br /> {<br /> gr.FillRectangle(b, 0,<br /> bounds.Top + 1, listBox.Width, bounds.Height &#8211; 1);<br /> }<br /> }<br /> <span style="color:#0000ff;">else</span><br /> {<br /> <span style="color:#0000ff;">using</span>(Brush b = <span style="color:#3300ff;">new</span> SolidBrush(Color.Gainsboro))<br /> {<br /> gr.FillRectangle(b, 0,<br /> bounds.Top, listBox.Width, bounds.Height);<br /> }<br /> }</p>
<p> <span style="color:#0000ff;">if </span>(listBox.Focused)<br /> {<br /> <span style="color:#0000ff;">using</span>(Pen p = new Pen(Color.RoyalBlue))<br /> {<br /> gr.DrawRectangle(p, <span style="color:#0000ff;">new</span> Rectangle(0,<br /> bounds.Top, listBox.Width, bounds.Height));<br /> }<br /> }<br /> }</p>
<p> <span style="color:#0000ff;">if </span>(IconIndex != -1 &amp;&amp; imageList1 != <span style="color:#0000ff;">null</span>)<br /> {<br /> img = imageList1.Images[IconIndex];<br /> Rectangle imgRect = <span style="color:#3300ff;">new</span> Rectangle(bounds.Left &#8211; DrawingPos, bounds.Top , img.Width, img.Height);<br /> gr.DrawImage(img, imgRect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);<br /> }</p>
<p> <span style="color:#0000ff;">using</span>(Brush b = <span style="color:#0000ff;">new</span> SolidBrush(TextColor))<br /> {<br /> gr.DrawString(Text, <span style="color:#0000ff;">this</span>.Font, b,<br /> <span style="color:#0000ff;">new</span> Point(bounds.Left &#8211; DrawingPos + XOffset_forIcon + 2, bounds.Top + 2));<br /> }<br />}</span>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack">Here is the code for activation and resizing of the scrollball </span></p>
<p><span class="smallblack"> </span></p>
<p><span style="border:thin solid gray;background-color:#ffcc66;"><span class="smallblack"><span style="color:#0000ff;">private void</span> ResizeListBoxAndHScrollBar()<br />{<br /> listBox.Width = this.Width;</p>
<p><span style="color:#0000ff;"> if </span>(listBox.Width &gt; (MaxStrignLen + XOffset_forIcon + 15))<br /> {<br /> hScrollBar1.Visible = false;<br /> listBox.Height = this.Height;<br /> }<br /> <span style="color:#0000ff;">else</span><br /> {<br /> hScrollBar1.Height = 18;<br /> listBox.Height = this.Height &#8211; this.hScrollBar1.Height;<br /> hScrollBar1.Top = this.Height &#8211; this.hScrollBar1.Height &#8211; 1;<br /> hScrollBar1.Width = this.Width;</p>
<p> hScrollBar1.Visible = true;<br /> hScrollBar1.Minimum = 0;<br /> hScrollBar1.Maximum = MaxStrignLen + XOffset_forIcon + 15;<br /> hScrollBar1.LargeChange = this.listBox.Width;<br /> hScrollBar1.Value = 0;<br /> }<br />}</span>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack">Is that all? Now we have the code for item drawing and the scroll bar. Unfortunately it is more complicated and that is the reason why other implementations of ColorListBox are not used in the commercial applications.The control we just created flickers when it is resized or the horizontal scrollbar moved.No matter how good your application is, just one flickering control on the GUI makes the product look unprofessional. It spoils the whole picture.</span></p>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack">How can be that fixed? There is a well known technique to eliminate the flickering. It is called Doublebuffering. The idea is that the actual drawing occurs in the memory and when it is completed, the image is copied to the GUI. Let?s use this technique.For that the class DoubleBuff has been written. <br /> It creates a bitmap image from the control and refreshes it when required.</span></p>
<p><span class="smallblack"> </span></p>
<p><span style="border:thin solid gray;background-color:#ffcc66;"><span class="smallblack"><span style="color:#0000ff;">public class</span> DoubleBuffer : IDisposable<br />{<br /> <span style="color:#0000ff;">private</span> Graphics graphics</p>
<p>;<br />
<span style="color:#0000ff;">private </span>Bitmap bitmap;<br /> <span style="color:#0000ff;">private </span>Control _ParentCtl;<br /> <span style="color:#0000ff;">private</span> Graphics CtlGraphics;</p>
<p> <span style="color:#0000ff;">public </span>DoubleBuffer(Control ParentCtl)<br /> {<br /> _ParentCtl = ParentCtl;<br /> bitmap = <span style="color:#0000ff;">new</span> Bitmap(_ParentCtl.Width , _ParentCtl.Height);<br /> graphics = Graphics.FromImage(bitmap);<br /> CtlGraphics = _ParentCtl.CreateGraphics();<br /> }</p>
<p> <span style="color:#0000ff;">public void</span> CheckIfRefreshBufferRequired()<br /> {<br /> <span style="color:#0000ff;">if </span>((_ParentCtl.Width != bitmap.Width) || (_ParentCtl.Height != bitmap.Height))<br /> {<br /> RefreshBuffer();<br /> }<br /> }</p>
<p> <span style="color:#0000ff;">public void</span> RefreshBuffer()<br /> {<br /> <span style="color:#0000ff;">if </span>(_ParentCtl == <span style="color:#0000ff;">null</span>)<br /> <span style="color:#0000ff;">return</span>;</p>
<p> <span style="color:#0000ff;">if </span>(_ParentCtl.Width == 0 || _ParentCtl.Height == 0)<span style="color:#339933;">// restoring event</span><br /> <span style="color:#0000ff;">return</span>;</p>
<p> <span style="color:#0000ff;">if </span>(bitmap != <span style="color:#0000ff;">null</span>)<br /> {<br /> bitmap.Dispose();<br /> bitmap = null;<br /> }</p>
<p> <span style="color:#0000ff;">if </span>(graphics != <span style="color:#0000ff;">null</span>)<br /> {<br /> graphics.Dispose();<br /> graphics = <span style="color:#0000ff;">null</span>;<br /> }</p>
<p> bitmap = <span style="color:#0000ff;">new</span> Bitmap(_ParentCtl.Width, _ParentCtl.Height);<br /> graphics = Graphics.FromImage(bitmap);</p>
<p> <span style="color:#0000ff;">if </span>(CtlGraphics != <span style="color:#0000ff;">null</span>)<br /> {<br /> CtlGraphics.Dispose();<br /> }</p>
<p> CtlGraphics = _ParentCtl.CreateGraphics();<br /> }</p>
<p> <span style="color:#0000ff;">public void</span> Render()<br /> {<br /> CtlGraphics.DrawImage(<br /> bitmap,<br /> _ParentCtl.Bounds,<br /> 0,<br /> 0,<br /> _ParentCtl.Width,<br /> _ParentCtl.Height,<br /> GraphicsUnit.Pixel);<br /> }</p>
<p> <span style="color:#0000ff;">public </span>Graphics BuffGraph<br /> {<br /> <span style="color:#0000ff;">get</span><br /> {<br /> <span style="color:#0000ff;">return</span> graphics;<br /> }<br /> }</p>
<p> <span style="color:#0000ff;">#region</span> IDisposable Members</p>
<p> <span style="color:#0000ff;">public void</span> Dispose()<br /> {<br /> <span style="color:#0000ff;">if </span>(bitmap != <span style="color:#0000ff;">null</span>)<br /> {<br /> bitmap.Dispose();<br /> }</p>
<p> <span style="color:#0000ff;">if </span>(graphics != <span style="color:#0000ff;">null</span>)<br /> {<br /> graphics.Dispose();<br /> }</p>
<p> <span style="color:#0000ff;">if </span>(CtlGraphics != <span style="color:#0000ff;">null</span>)<br /> {<br /> CtlGraphics.Dispose();<br /> }<br /> }</p>
<p> <span style="color:#0000ff;">#endregion</span><br />}</span>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack">Now we do not draw the items on GUI directly. We draw them on memory based bitmap.But our control still keeps flickering. Why? One more step is left ? the original control repaints the background. But how to stop doing that? As I mentioned, the overridable method OnPaintBackGround() is not hooked to the events and overriding them will do nothing. <br /> In the view of the above the only way to block the original painting of the background is to block the <strong>WM_ERASEBKGND</strong> event in<span>&nbsp; </span>WndProc() method. <br /> We have to override WndProc() in specifically created for that class.</span></p>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack"><strong>The wheel scrolling</strong></span></p>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack">The mouse wheel event processing has also to be fixed. The most sensible way is to block <strong>WM_MOUSEWHEEL</strong> event and convert it to vertical scroll bar event. Newly created events are sent directly using Windows API SendMessage().</span></p>
<p><span class="smallblack"> </span></p>
<p><span style="border:thin solid gray;background-color:#ffcc66;"><span class="smallblack"><span style="color:#0000ff;">private void</span> GetXY(IntPtr Param,<span style="color:#0000ff;"> out int</span> X, <span style="color:#0000ff;">out int</span> Y)<br />{<br /> <span style="color:#0000ff;">byte</span>[] byts = System.BitConverter.GetBytes((<span style="color:#0000ff;">int</span>)Param);<br /> X = BitConverter.ToInt16(byts, 0);<br /> Y = BitConverter.ToInt16(byts, 2);<br />}</p>
<p><span style="color:#0000ff;">protected override void</span> WndProc(<span style="color:#0000ff;">ref</span> Message m)<br />{<br /> <span style="color:#0000ff;">switch</span> (m.Msg)<br /> {<br /> <span style="color:#0000ff;">case</span> (<span style="color:#0000ff;">int</span>)Msg.WM_ERASEBKGND:</p>
<p> <span style="color:#0000ff;">if </span>(_BlockEraseBackGnd)<br /> {<br /> <span style="color:#0000ff;">return</span>;<br /> }</p>
<p> <span style="color:#0000ff;">break</span>;</p>
<p> <span style="color:#0000ff;">case</span> (<span style="color:#0000ff;">int</span>)Msg.WM_MOUSEWHEEL:</p>
<p> <span style="color:#0000ff;">int </span>X;<br /> <span style="color:#0000ff;">int </span>Y;</p>
<p> _BlockEraseBackGnd = <span style="color:#0000ff;">false</span>;</p>
<p> GetXY(m.WParam, <span style="color:#0000ff;">out</span> X, <span style="color:#0000ff;">out</span> Y);</p>
<p> <span style="color:#0000ff;">if </span>(Y &gt;0)<br /> {<br /> SendMessage(<span style="color:#0000ff;">this</span>.Handle, (<span style="color:#0000ff;">int</span>)Msg.WM_VSCROLL,(IntPtr)SB_LINEUP,IntPtr.Zero);<br /> }<br /> <span style="color:#0000ff;">else</span><br /> {<br /> SendMessage(<span style="color:#0000ff;">this</span>.Handle, (<span style="color:#0000ff;">int</span>)Msg.WM_VSCROLL,(IntPtr)SB_LINEDOWN,IntPtr.Zero);<br /> }<br /> <span style="color:#0000ff;">return</span>;</p>
<p> <span style="color:#0000ff;">case</span> (<span style="color:#3300ff;">int</span>)Msg.WM_VSCROLL:<br /> <span style="color:#0000ff;">case</span> (<span style="color:#0000ff;">int</span>)Msg.WM_KEYDOWN:</p>
<p> _BlockEraseBackGnd = <span style="color:#0000ff;">false</span>;</p>
<p> if (UpdateEv != <span style="color:#0000ff;">null</span>)<br /> {<br /> UpdateEv(<span style="color:#0000ff;">null</span>, <span style="color:#0000ff;">null</span>);<br /> }<br /> <span style="color:#3300ff;">break</span>;<br /> }</p>
<p> <span style="color:#0000ff;">base</span>.WndProc (<span style="color:#0000ff;">ref</span> m);</p>
<p>}</span>
<p><span class="smallblack"> </span></p>
<p align="left"><span class="smallblack"><strong>Populating the control</strong></span></p>
<p><span class="smallblack"> </span></p>
<p><span class="smallblack">The main method for populating the control is <span style="color:#3300ff;">public void AddItem(object Item, int IconIndex, Color TxtColor);<br /> </span>Where the Item can be anything. Any class that has ToString() method. You may create you own class and override the method ToString() or you can simply use strings.</span></p>
<p><span class="smallblack"> </span></p>
<p><span style="border:thin solid gray;background-color:#ffcc66;"><span class="smallblack"><span style="color:#0000ff;">public void</span> AddItem(<span style="color:#0000ff;">object</span> Item, <span style="color:#0000ff;">int</span> IconIndex, Color TxtColor)<br />{<br /> ObjectHolder oh = new ObjectHolder(IconIndex, Item, TxtColor);</p>
<p> UseDoubleBuffering = <span style="color:#0000ff;">false</span>;<br /> listBox.Items.Add(oh);<br /> ResizeListBoxAndHScrollBar();<br />}</span>
<p><span class="smallblack"> </span></p>
<p align="left"><span class="smallblack">The internal <span style="color:#0000ff;">ListBox</span> and <span style="color:#3300ff;"> HScrollBar</span> were made public to have an access to them.</span></p>
<p><sp</p>
<p>an class="smallblack"> </span></p>
<h3 align="center"><span class="smallblack">Final touch</span></h3>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack"> New control now works fine. Though one last thing that is left &#8211; the <span style="font-size:12pt;font-family:&#39;Times New Roman&#39;;"> appearance </span>of the control. On Window 2000 it looks pretty normal but on WinXP it looks like the screenshot below. </span></p>
<p><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack"> </span></p>
<h3 align="center"><span class="smallblack"><img src="http://members.iinet.net/%7eletchik/DotNetRemoting/Articles/ListUnprocessed.gif" alt="" /></span></h3>
<p><span class="smallblack"> </span><span class="smallblack"> </span></p>
<p class="MsoNormal"><span class="smallblack">Vertical scroolbar has XP style but the horizontal one has standard appearance.To change this the manifest has to be applied. <br /> Basically manifest file specifies the DLL where the common controls reside. </span></p>
<p><span class="smallblack"> </span></p>
<p><span style="border:thin solid gray;background-color:#ffcc66;"><span class="smallblack">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br />&lt;assembly xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot; manifestVersion=&quot;1.0&quot;&gt;<br />&lt;assemblyIdentity<br /> version=&quot;1.0.0.0&quot;<br /> processorArchitecture=&quot;X86&quot;<br /> name=&quot;&quot;<br /> type=&quot;win32&quot;<br />/&gt;<br />&lt;description&gt;Your app description here&lt;/description&gt;<br />&lt;dependency&gt;<br /> &lt;dependentAssembly&gt;<br /> &lt;assemblyIdentity<br /> type=&quot;win32&quot;<br /> name=&quot;Microsoft.Windows.Common-Controls&quot;<br /> version=&quot;6.0.0.0&quot;<br /> processorArchitecture=&quot;X86&quot;<br /> publicKeyToken=&quot;6595b64144ccf1df&quot;<br /> language=&quot;*&quot;<br /> /&gt;<br /> &lt;/dependentAssembly&gt;<br />&lt;/dependency&gt;<br />&lt;/assembly&gt;<br /></span>
<p><span class="smallblack"> </span></p>
<p><span class="smallblack"> The manifest file has to be in the same directory where the applications starts. To avoid having this inconvenient file in the run directory, the manifest can be injected directly into the executable assembly. For automating this task the utility program <strong>DotNetManifester.exe</strong> has been written. You can use this utility to inject the manifest directly into the program. </span></p>
<p><span class="smallblack">Full source code and the latest binaries&nbsp;of the control can be found in <span style="color:#000011;"><strong>ToolBox</strong> <strong>section</strong></span><a href="http://dotnetremoting.com/"><strong><span style="color:#0000ff;">here</span></strong> </a>as well as <strong>DotNetManifester.exe .</strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/07/net-color-listbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File Copier &#8211; WinForms Demonstration Program</title>
		<link>http://www.csharphelp.com/2007/06/file-copier-winforms-demonstration-program/</link>
		<comments>http://www.csharphelp.com/2007/06/file-copier-winforms-demonstration-program/#comments</comments>
		<pubDate>Sat, 30 Jun 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Win Forms]]></category>
		<category><![CDATA[I/O]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=590</guid>
		<description><![CDATA[Here is source for a file copier program that uses WinForms. using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Windows.Forms;/// &#60;remarks&#62;/// File Copier &#8211; WinForms demonstration program/// (c) Copyright 2001 Liberty Associates, Inc./// &#60;/remarks&#62;namespace FileCopier{ /// &#60;summary&#62; /// Form demonstrating Windows Forms implementation /// &#60;/summary&#62; // &#60; declarations of Windows widgets cut here &#62; public class [...]]]></description>
			<content:encoded><![CDATA[<p><span class="smallblack">Here is source for a file copier program that uses WinForms.</span></p>
<p><span class="smallblack">using System;<br />using System.Collections;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.IO;<br />using System.Windows.Forms;<br />/// &lt;remarks&gt;<br />/// File Copier &#8211; WinForms demonstration program<br />/// (c) Copyright 2001 Liberty Associates, Inc.<br />/// &lt;/remarks&gt;<br />namespace FileCopier<br />{<br /> /// &lt;summary&gt;<br /> /// Form demonstrating Windows Forms implementation<br /> /// &lt;/summary&gt;<br /> // &lt; declarations of Windows widgets cut here &gt;<br /> public class Form1 : System.Windows.Forms.Form<br /> {<br /> /// &lt;summary&gt;<br /> /// internal class which knows how to compare<br /> /// two files we want to sort large to small,<br /> /// so reverse the normal return values.<br /> /// &lt;/summary&gt;<br /> public class FileComparer : IComparer<br /> {<br /> public int Compare (object f1, object f2)<br /> {<br /> FileInfo file1 = (FileInfo) f1;<br /> FileInfo file2 = (FileInfo) f2;<br /> if (file1.Length &gt; file2.Length)<br /> {<br /> return -1;<br /> }<br /> if (file1.Length &lt; file2.Length)<br /> {<br /> return 1;<br /> }<br /> return 0;<br /> }<br /> }<br /> public Form1( )<br /> {<br /> //<br /> // Required for Windows Form Designer support<br /> //<br /> InitializeComponent( );<br /> // fill the source and target directory trees<br /> FillDirectoryTree(tvwSource, true);<br /> FillDirectoryTree(tvwTargetDir, false);<br /> }<br /> /// &lt;summary&gt;<br /> /// Fill the directory tree for either the Source or<br /> /// Target TreeView.<br /> /// &lt;/summary&gt;<br /> private void FillDirectoryTree(<br /> TreeView tvw, bool isSource)<br /> {<br /> // Populate tvwSource, the Source TreeView,<br /> // with the contents of<br /> // the local hard drive.<br /> // First clear all the nodes.<br /> tvw.Nodes.Clear( );<br /> // Get the logical drives and put them into the<br /> // root nodes. Fill an array with all the<br /> // logical drives on the machine.<br /> string[] strDrives =<br /> Environment.GetLogicalDrives( );<br /> // Iterate through the drives, adding them to the tree.<br /> // Use a try/catch block, so if a drive is not ready,<br /> // e.g. an empty floppy or CD,<br /> // it will not be added to the tree.<br /> foreach (string rootDirectoryName in strDrives)<br /> {<br /> if (rootDirectoryName != @\&quot;C:\\&quot;)<br /> continue;<br /> try<br /> {<br /> // Fill an array with all the first level<br /> // subdirectories. If the drive is<br /> // not ready, this will throw an exception.<br /> DirectoryInfo dir =<br /> new DirectoryInfo(rootDirectoryName);<br /> dir.GetDirectories( );<br /> TreeNode ndRoot = new TreeNode(rootDirectoryName);<br /> // Add a node for each root directory.<br /> tvw.Nodes.Add(ndRoot);<br /> // Add subdirectory nodes.<br /> // If TreeView is the source,<br /> // then also get the filenames.<br /> if (isSource)<br /> {<br /> GetSubDirectoryNodes(<br /> ndRoot, ndRoot.Text, true);<br /> }<br /> else<br /> {<br /> GetSubDirectoryNodes(<br /> ndRoot, ndRoot.Text, false);<br /> }<br /> }<br /> catch (Exception e)<br /> {<br /> // Catch any errors such as<br /> // Drive not ready.<br /> MessageBox.Show(e.Message);<br /> }<br /> }<br /> } // close for FillSourceDirectoryTree<br /> /// &lt;summary&gt;<br /> /// Gets all the subdirectories below the<br /> /// passed in directory node.<br /> /// Adds to the directory tree.<br /> /// The parameters passed in at the parent node<br /> /// for this subdirectory,<br /> /// the full pathname of this subdirectory,<br /> /// and a Boolean to indicate<br /> /// whether or not to get the files in the subdirectory.<br /> /// &lt;/summary&gt;<br /> private void GetSubDirectoryNodes(<br /> TreeNode parentNode, string fullName, bool getFileNames)<br /> {<br /> DirectoryInfo dir = new DirectoryInfo(fullName);<br /> DirectoryInfo[] dirSubs = dir.GetDirectories( );<br /> // Add a child node for each subdirectory.<br /> foreach (DirectoryInfo dirSub in dirSubs)<br /> {<br /> // do not show hidden folders<br /> if ( (dirSub.Attributes &amp; FileAttributes.Hidden)<br /> != 0 )<br /> {<br /> continue;<br /> }<br /> /// &lt;summary&gt;<br /> /// Each directory contains the full path.<br /> /// We need to split it on the backslashes,<br /> /// and only use<br /> /// the last node in the tree.<br /> /// Need to double the backslash since it<br /> /// is normally<br /> /// an escape character<br /> /// &lt;/summary&gt;<br /> TreeNode subNode = new TreeNode(dirSub.Name);<br /> parentNode.Nodes.Add(subNode);<br /> // Call GetSubDirectoryNodes recursively.<br /> GetSubDirectoryNodes(<br /> subNode,dirSub.FullName,getFileNames);<br /> }<br /> if (getFileNames)<br /> {<br /> // Get any files for this node.<br /> FileInfo[] files = dir.GetFiles( );<br /> // After placing the nodes,<br /> // now place the files in that subdirectory.<br /> foreach (FileInfo file in files)<br /> {<br /> TreeNode fileNode = new TreeNode(file.Name);<br /> parentNode.Nodes.Add(fileNode);<br /> }<br /> }<br /> }<br /> // &lt; boilerplate code cut here &gt;<br /> /// &lt;summary&gt;<br /> /// The main entry point for the application.<br /> /// &lt;/summary&gt;<br /> [STAThread]<br /> static void Main( )<br /> {<br /> Application.Run(new Form1( ));<br /> }<br /> /// &lt;summary&gt;<br /> /// Create an ordered list of all<br /> /// the selected files, copy to the<br /> /// target directory<br /> /// &lt;/summary&gt;<br /> private void btnCopy_Click(object sender,<br /> System.EventArgs e)<br /> {<br /> // get the list<br /> ArrayList fileList = GetFileList( );<br /> // copy the files<br /> foreach (FileInfo file in fileList)<br /> {<br /> try<br /> {<br /> // update the label to show progress<br /> lblStatus.Text = \&quot;Copying \&quot; + txtTargetDir.Text +<br /> \&quot;\\\&quot; + file.Name + \&quot;&#8230;\&quot;;<br /> Application.DoEvents( );<br /> // copy the file to its destination location<br /> file.CopyTo(txtTargetDir.Text + \&quot;\\\&quot; +<br /> file.Name,chkOverwrite.Checked);<br /> }<br /> catch // (Exception ex)<br /> {<br /> // you may want to do more than just show the message<br /> // MessageBox.Show(ex.Message);<br /> }<br /> }<br /> lblStatus.Text = \&quot;Done.\&quot;;<br /> Application.DoEvents( );<br /> }<br /> /// &lt;summary&gt;<br /> /// on cancel, exit<br /> /// &lt;/summary&gt;<br /> private void btnCancel_Click(object sender, System.EventArgs e)<br /> {<br /> Application.Exit( );<br /> }<br /> /// &lt;summary&gt;<br /> /// Tell the root of each tree to uncheck<br /> /// all the nodes below<br /> /// &lt;/summary&gt;<br /> private void btnClear_Click(object sender, System.EventArgs e)<br /> {<br /> // get the top most node for each drive<br /> // and tell it to clear recursively<br /> foreach (TreeNode node in tvwSource.Nodes)<br /> {<br /> SetCheck(node, false);<br /> }<br /> }<br /> /// &lt;summary&gt;<br /> /// check that the user does want to delete<br /> /// Make a list and delete each in turn<br /> /// &lt;/summary&gt;<br /> private void btnDelete_Click(object sender, System.EventArgs e)<br /> {<br /> // ask them if they are sure<br /> System.Windows.Forms.DialogResult result =<br /> MessageBox.Show(<br /> \&quot;Are you quite sure?\&quot;, // msg<br /> \&quot;Delete Files\&quot;, // caption<br /> MessageBoxButtons.OKCancel, // buttons<br /> MessageBoxIcon.Exclamation, // icons<br /> MessageBoxDefaultButton.Button2); // default button<br /> // if they are sure&#8230;<br /> if (result == System.Windows.Forms.DialogResult.OK)<br /> {<br /> // iterate through the list and delete them.<br /> // get the list of selected files<br /> ArrayList fileNames = GetFileList( );<br /> foreach (FileInfo file in fileNames)<br /> {<br /> try<br /> {<br /> // update the label to show progress<br /> lblStatus.Text = \&quot;Deleting \&quot; +<br /> txtTargetDir.Text + \&quot;\\\&quot; +<br /> file.Name + \&quot;&#8230;\&quot;;<br /> Application.DoEvents( );<br /> // Danger Will Robinson!<br /> file.Delete( );<br /> }<br /> catch (Exception ex)<br /> {<br /> //<br />
you may<br />
want to do more than<br /> // just show the message<br /> MessageBox.Show(ex.Message);<br /> }<br /> }<br /> lblStatus.Text = \&quot;Done.\&quot;;<br /> Application.DoEvents( );<br /> }<br /> }<br /> /// &lt;summary&gt;<br /> /// Get the full path of the chosen directory<br /> /// copy it to txtTargetDir<br /> /// &lt;/summary&gt;<br /> private void tvwTargetDir_AfterSelect(<br /> object sender,<br /> System.Windows.Forms.TreeViewEventArgs e)<br /> {<br /> // get the full path for the selected directory<br /> string theFullPath = GetParentString(e.Node);<br /> // if it is not a leaf, it will end with a backslash<br /> // remove the backslash<br /> if (theFullPath.EndsWith(\&quot;\\\&quot;))<br /> {<br /> theFullPath =<br /> theFullPath.Substring(0,theFullPath.Length-1);<br /> }<br /> // insert the path in the text box<br /> txtTargetDir.Text = theFullPath;<br /> }<br /> /// &lt;summary&gt;<br /> /// Mark each node below the current<br /> /// one with the current value of checked<br /> /// &lt;/summary&gt;<br /> private void tvwSource_AfterCheck(object sender,<br /> System.Windows.Forms.TreeViewEventArgs e)<br /> {<br /> // Call a recursible method.<br /> // e.node is the node which was checked by the user.<br /> // The state of the check mark is already<br /> // changed by the time you get here.<br /> // Therefore, we want to pass along<br /> // the state of e.node.Checked.<br /> SetCheck(e.Node,e.Node.Checked);<br /> }<br /> /// &lt;summary&gt;<br /> /// recursively set or clear check marks<br /> /// &lt;/summary&gt;<br /> private void SetCheck(TreeNode node, bool check)<br /> {<br /> // set this node&#39;s check mark<br /> node.Checked = check;<br /> // find all the child nodes from this node<br /> foreach (TreeNode n in node.Nodes)<br /> {<br /> // if the child is a leaf<br /> // just check it (or uncheck it)<br /> if (node.Nodes.Count == 0)<br /> {<br /> node.Checked = check;<br /> }<br /> // if the child is a node in the tree, recurse<br /> else<br /> {<br /> SetCheck(n,check);<br /> }<br /> }<br /> }<br /> /// &lt;summary&gt;<br /> /// Given a node and an array list<br /> /// fill the list with the names of<br /> /// all the checked files<br /> /// &lt;/summary&gt;<br /> // Fill the ArrayList with the full paths of<br /> // all the feils checked<br /> private void GetCheckedFiles(TreeNode node,<br /> ArrayList fileNames)<br /> {<br /> // if this is a leaf&#8230;<br /> if (node.Nodes.Count == 0)<br /> {<br /> // if the node was checked&#8230;<br /> if (node.Checked)<br /> {<br /> // get the full path and add it to the arrayList<br /> string fullPath = GetParentString(node);<br /> fileNames.Add(fullPath);<br /> }<br /> }<br /> else // if this node is not a leaf<br /> {<br /> // call this for all the subnodes<br /> foreach (TreeNode n in node.Nodes)<br /> {<br /> GetCheckedFiles(n,fileNames);<br /> }<br /> }<br /> }<br /> /// &lt;summary&gt;<br /> /// Given a node, return the<br /> /// full pathname<br /> /// &lt;/summary&gt;<br /> private string GetParentString(TreeNode node)<br /> {<br /> // if this is the root node (c:\) return the text<br /> if(node.Parent == null)<br /> {<br /> return node.Text;<br /> }<br /> else<br /> {<br /> // recurse up and get the path then<br /> // add this node and a slash<br /> // if this node is the leaf, don&#39;t add the slash<br /> return GetParentString(node.Parent) + node.Text +<br /> (node.Nodes.Count == 0 ? \&quot;\&quot; : \&quot;\\\&quot;);<br /> }<br /> }<br /> /// &lt;summary&gt;<br /> /// shared by delete and copy<br /> /// creates an ordered list of all<br /> /// the selected files<br /> /// &lt;/summary&gt;<br /> private ArrayList GetFileList( )<br /> {<br /> // create an unsorted array list of the full filenames<br /> ArrayList fileNames = new ArrayList( );<br /> // fill the fileNames ArrayList with the<br /> // full path of each file to copy<br /> foreach (TreeNode theNode in tvwSource.Nodes)<br /> {<br /> GetCheckedFiles(theNode, fileNames);<br /> }<br /> // Create a list to hold the fileInfo objects<br /> ArrayList fileList = new ArrayList( );<br /> // for each of the filenames we have in our unsorted list<br /> // if the name corresponds to a file (and not a directory)<br /> // add it to the file list<br /> foreach (string fileName in fileNames)<br /> {<br /> // create a file with the name<br /> FileInfo file = new FileInfo(fileName);<br /> // see if it exists on the disk<br /> // this fails if it was a directory<br /> if (file.Exists)<br /> {<br /> // both the key and the value are the file<br /> // would it be easier to have an empty value?<br /> fileList.Add(file);<br /> }<br /> }<br /> // Create an instance of the IComparer interface<br /> IComparer comparer = (IComparer) new FileComparer( );<br /> // pass the comparer to the sort method so that the list<br /> // is sorted by the compare method of comparer.<br /> fileList.Sort(comparer);<br /> return fileList;<br /> }<br /> }<br />}<br />/// &lt;summary&gt;<br />/// Mark each node below the current<br />/// one with the current value of checked<br />/// &lt;/summary&gt;<br />protected void tvwSource_AfterCheck (<br />object sender, System.Windows.Forms.TreeViewEventArgs e)<br />{<br />}<br /></span>
<p><span class="smallblack">C:\Documents and Settings\Nikola\MyDocuments\Visual Studio Projects\WindowsApplication1\Form1.cs(420): Anamespace does not directly contain members such as fields or methods</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/06/file-copier-winforms-demonstration-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coloring The Console</title>
		<link>http://www.csharphelp.com/2007/06/coloring-the-console/</link>
		<comments>http://www.csharphelp.com/2007/06/coloring-the-console/#comments</comments>
		<pubDate>Sun, 17 Jun 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Win Forms]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=577</guid>
		<description><![CDATA[When working with console applications in c#,black screens with white foregrounds are always used. We can change theforeground color as well as background color of our console applicationby using win32 API SetConsoleTextAttribute(). SetConsoleTextAttribute takes two arguments 1. Handle to console screen buffer2. character attributesBOOL SetConsoleTextAttribute( HANDLE hConsoleOutput, WORD wAttributes); We can get the handle to [...]]]></description>
			<content:encoded><![CDATA[<p><span class="smallblack">When working with console applications in c#,black screens with white foregrounds are always used. We can change theforeground color as well as background color of our console applicationby using win32 API SetConsoleTextAttribute().</span></p>
<p><span class="smallblack">SetConsoleTextAttribute takes two arguments <br />1. Handle to console screen buffer<br />2. character attributes<br />BOOL SetConsoleTextAttribute(<br /> HANDLE hConsoleOutput,<br /> WORD wAttributes<br />);<br /></span>
<p><span class="smallblack">We can get the handle to the console screenbuffer by using a function of win32 API i.e. GetStdHandle(),which takesa parameter and returns a handle for input, output or error device.We give -10 for input,-11 for output and -12 for error device asparameter to GetStdHandle function.We have attributes for fore ground and background colors like 0x0001for fore ground blue and 0&#215;0010 for back ground blue.</span></p>
<p><span class="smallblack">How To Use Win32 API Function in C#.</span></p>
<p><span class="smallblack">First of all declare the function using DllImport attribute. An API function must be declared static extern.DllImport is used to call an unmanaged code inside a mangaed code, so we must have to use it to call unmanaged win32 APIs.</span></p>
<p><span class="smallblack">Let&#39;s start an example</span></p>
<p><span class="smallestblack"><span class="smallblack">using System;<br />using System.Runtime.InteropServices; // for DllImport attribute </p>
<p>namespace color_console<br />{</p>
<p> class Class1<br /> {</p>
<p> static void Main(string[] args)<br /> {<br /> //<br /> // TODO: Add code to start application here<br /> //<br /> Class1 c =new Class1();<br /> c.change();</p>
<p> }<br /> [DllImport(&quot;kernel32.dll&quot;, SetLastError=true)]<br /> public static extern bool SetConsoleTextAttribute(<br /> IntPtr hConsoleOutput,<br /> CharacterAttributes wAttributes); /* declaring the setconsoletextattribute function*/</p>
<p> [DllImport(&quot;kernel32.dll&quot;)]<br /> public static extern IntPtr GetStdHandle(int nStdHandle); //declaring the getstdhandle funtion <br /> /* to get thehandle that would be used in setConsoletextattribute function */<br /> void change()<br /> {<br /> IntPtr hOut; /* declaring varianle to get handle*/<br /> hOut= GetStdHandle(-11);/* -11 is sent for output device*/ </p>
<p> /*Displaying text in different colors and background colors*/</p>
<p> SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_BLUE );<br /> Console.WriteLine(&quot; Subhan ALLAH &quot;);</p>
<p> SetConsoleTextAttribute(hOut, CharacterAttributes.BACKGROUND_RED);<br /> Console.WriteLine(&quot; Alkhamdolillah &quot;);<br /> SetConsoleTextAttribute(hOut, CharacterAttributes.BACKGROUND_GREEN );<br /> Console.WriteLine(&quot; Allah O Akbar &quot;);<br /> SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_RED );<br /> Console.WriteLine(&quot; Pakistan &quot;);</p>
<p> }<br />/* This enumeration lists all of the character attributes. You can combine attributes to */<br />/* achieve specific effects.*/</p>
<p> public enum CharacterAttributes<br /> {<br /> FOREGROUND_BLUE = 0&#215;0001,<br /> FOREGROUND_GREEN = 0&#215;0002,<br /> FOREGROUND_RED = 0&#215;0004,<br /> FOREGROUND_INTENSITY = 0&#215;0008,<br /> BACKGROUND_BLUE = 0&#215;0010,<br /> BACKGROUND_GREEN = 0&#215;0020,<br /> BACKGROUND_RED = 0&#215;0040,<br /> BACKGROUND_INTENSITY = 0&#215;0080,<br /> COMMON_LVB_LEADING_BYTE = 0&#215;0100,<br /> COMMON_LVB_TRAILING_BYTE = 0&#215;0200,<br /> COMMON_LVB_GRID_HORIZONTAL = 0&#215;0400,<br /> COMMON_LVB_GRID_LVERTICAL = 0&#215;0800,<br /> COMMON_LVB_GRID_RVERTICAL = 0&#215;1000,<br /> COMMON_LVB_REVERSE_VIDEO = 0&#215;4000,<br /> COMMON_LVB_UNDERSCORE = 0&#215;8000<br /> }</p>
<p> }</p>
<p>}<br /></span>
<p><span class="smallblack">We can also change the font and cursor ofconsole application using win32 APIs.Changing the title of the console is also easy, just useSetConsoleTitle()function and provide a string to it as a parameter.That would be title of console. You can do it easily</span></p>
<p><span class="smallblack">[DllImport(&quot;kernel32.dll&quot;)<br /> public static extern bool SetConsoleTitle(String lpConsoleTitle);<br />First declare setconsoletitle function and then use it<br />SetConsoleTitle(&quot; ALlah O Akbar &#8230; &quot;);<br /></span>
<p><span class="smallblack">By<br />Kashif Bilal<br />kashiff@gmail.com</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/06/coloring-the-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MDI With C#</title>
		<link>http://www.csharphelp.com/2007/05/mdi-with-c/</link>
		<comments>http://www.csharphelp.com/2007/05/mdi-with-c/#comments</comments>
		<pubDate>Thu, 24 May 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Win Forms]]></category>
		<category><![CDATA[MDI]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=553</guid>
		<description><![CDATA[MDI (Multiple Document Interface) is nothing but a way of displaying windows form where there is atleast one parent and manychild windows eg. word Excel Powerpoint kind of windows where each document , sheet or slide act as a child under the parent container window. SDI(Single document Interface) examples are Windows Explorer,Internet explorer,Notepad etc&#8230;where only [...]]]></description>
			<content:encoded><![CDATA[<p><span class="smallblack">MDI (Multiple Document Interface) is nothing but a way of displaying windows form where there is atleast one parent and manychild windows eg. word Excel Powerpoint kind of windows where each document , sheet or slide act as a child under the parent container window.</span></p>
<p><span class="smallblack">SDI(Single document Interface) examples are Windows Explorer,Internet explorer,Notepad etc&#8230;where only one window acts as an interface.</span></p>
<p><span class="smallblack">If you are a beginner(or intermediate) and want to develop an MDI application with basic functionality using the powerful C# language checkout the following step-by-step guide to develop. Even people coming from VB6 background face lots of problem because of the pure OOPs usage in C#. Follow this small step by step walkthrough to make a small MDI application.</span></p>
<p><span class="smallblack">1&gt; Goto File-&gt;New-&gt;Blank Solution<br />2&gt; Select Visual C# Projects in Project Types<br />3&gt; Select WindowsApplication in Templates<br />4&gt; Type for eg. myBestMDI in the Name textbox<br />5&gt; By Clicking the browse button select the location &amp; Click OK</p>
<p>CREATING ALL THE NECESSARY FORMS &amp; CODE THEM<br />============================================</p>
<p>Creating the main MDI form(frmMDIMain) to act as a container<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />1&gt; In the View-&gt;Solution Explorer click Form1 only once<br />2&gt; Locate the property FileName and type &quot;frmMDIMain.cs&quot;<br />3&gt; In the Solution Explorer now doubleclick frmMDIMain <br />4&gt; Locate the property (Name) and type &quot;frmMDIMain&quot;<br />5&gt; Locate the property Text and type &quot;This is the Parent&quot;<br />6&gt; Locate the property IsMDIContainer and set it to true<br />7&gt; Locate the property WindowState and set it to Maximized</p>
<p>Creating the child form (frmMChild) to demonstrate multiple instance<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />1&gt; Goto Project Menu-Add Windows Forms &amp; type frmMChild<br />2&gt; In the Solution Explorer now doubleclick frmMChild<br />3&gt; Locate the property Text and type &quot;This is the Multi Instance Child&quot;<br />4&gt; Locate the property size &amp; set it to 568, 464</p>
<p>Creating the child form (frmSChild) to demonstrate Single instance<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />1&gt; Goto Project Menu-Add Windows Forms &amp; type frmSChild<br />2&gt; In the Solution Explorer now doubleclick frmSChild<br />3&gt; Locate the property Text and type &quot;This is the Single Instance Child&quot;<br />4&gt; Locate the property size &amp; set it to 568, 464</p>
<p>Creating the About form (frmAbout) to give information about this product<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />1&gt; Goto Project Menu-Add Windows Forms &amp; type frmAbout<br />2&gt; In the Solution Explorer now doubleclick frmAbout<br />3&gt; Locate the property Text and type &quot;About My Best MDI&quot;<br />4&gt; Locate the property size &amp; set it to 448, 304<br />5&gt; Locate the property FormBorderstyle &amp; set it to FixedToolWindow</p>
<p>Creating the Splash form (frmSplash) to display the welcome information with company logo<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />1&gt; Goto Project Menu-Add Windows Forms &amp; type frmSplash<br />2&gt; In the Solution Explorer now doubleclick frmSplash<br />3&gt; Locate the property size and set it to 448, 320<br />4&gt; Locate the property ControlBox and set it to False<br />5&gt; Locate the property FormBoderStyle and set it to None<br />6&gt; Locate the property StartupPosition and set it to CenterScreen<br />7&gt; Locate the property BackGroundImage and browse a nice image along with your company logo<br />8&gt; Locate the property cursor &amp; set it to waitCursor</p>
<p>Adding a timer control to the splash screen for holding it for few seconds so <br />that the user can read it.<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />1&gt; Goto View-&gt;Toolbox and Double click Timer control<br />2&gt; Locate timer1 control &amp; click it once<br />3&gt; Set its Interval property to 2000 i.e. in milliseconds<br />4&gt; Set its Enabled property to true<br />5&gt; Double click to reach its Tick event<br />type :- <br />timer1.Enabled = false;<br />this.Close();<br />Adding two classes 1 to act as the Main startup class(clsMain) &amp; 1 for holding<br />Global objects(clsGlobal)<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />1&gt; In the Solution explorer right click the Project Name myBestMdi<br />2&gt; Click Add-&gt;New Folder and type classes<br />3&gt; right click the Folder classes<br />4&gt; Click Add-&gt;Add New Item and class and type clsGlobal in name<br />Note:- myBestMDI.Classes is automatically taken as the namespace due to folder level<br />5&gt; change the modifiers for the class from<br /> public class clsGlobal <br />to <br /> public sealed class clsGlobal <br />(This is to protect an instantiation of this class)</p>
<p>6&gt; Just after the curly braces of the class starts paste the following line<br />public static frmMDIMain g_objfrmMDIMain;<br />//this is to declare a global static reference to our MDI parent so that the same <br />//instance is referred across all child with no extra line of code</p>
<p>7&gt; Again in the Solution explorer right click the Folder classes<br />8&gt; Click Add-&gt;Add New Item and class and type clsMain in name<br />9&gt; just below the constructor clsMain function in the clsMain class paste the following <br />snippet<br />[STAThread]<br /> static void Main() <br /> {<br /> try<br /> {<br /> frmSplash objfrmSplash = new frmSplash();<br /> objfrmSplash.ShowDialog();<br /> clsGlobal.g_objfrmMDIMain = new frmMDIMain();<br /> Application.Run(clsGlobal.g_objfrmMDIMain);<br /> }<br /> catch(Exception ex)<br /> {<br /> MessageBox.Show(ex.Message,&quot;My Best MDI&quot;,MessageBoxButtons.OK,MessageBoxIcon.Stop); <br /> }<br /> }<br />//This is the Single Threaded Apartment Model(out of our scope) of the application which will run the Main function<br />//when the application starts<br />10&gt; Since we are using Application class and MessageBox functions in the above code we need a <br />add the foolowing line on the top<br />using System.Windows.Forms;<br />11&gt; Now go to frmMain now and from its code window remove the following piece of code<br />[STAThread]<br /> static void Main() <br /> {<br /> Application.Run(new Form1());<br /> }<br />//because we cannot have two Main function.We are invoking everything from clsMain</p>
<p>Creating menus in the main MDI form<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />1&gt; Click View-&gt;Designer of frmMdiMain<br />2&gt; Goto Toolbox and add a double click MainMenu control<br />3&gt; Click once on the typehere menu <br />4&gt; Locate the property Name &amp; set it to mnuFile<br />5&gt; Locate the property Text &amp; set it to &amp;File<br />Note:- &amp; is for underscore which will enable the Hot key &#39;F&#39;<br />6&gt; Same way click on the sub menu TypeHere box<br />7&gt; Locate the property Name &amp; set it to mnuFileNewMultiple<br />8&gt; Locate the property Text &amp; set it to &amp;New Multiple<br />9&gt; Locate the property ShortCut &amp; choose CtrlN<br />10&gt; Same way click on the sub menu TypeHere box<br />11&gt; Locate the property Name &amp; set it to mnuFileNewSingle<br />12&gt; Locate the property Text &amp; set it to New &amp;Single<br />13&gt; click on the sub menu TypeHere box<br />14&gt; Locate the property Name &amp; set it to mnuFileCloseChild<br />15&gt; Locate the property Text &amp; set it to &amp;Close Child<br />16&gt; click on the sub menu TypeHere box<br />17&gt; Locate the property Name &amp; set it to mnuFileSep1<br />18&gt; Locate the property Tex</p>
<p>t &amp;<br />
set it to &#8211; <br />Note &#8211; is a hyphen which will automatically put a whole seperator<br />19&gt; click on the sub menu TypeHere box<br />20&gt; Locate the property Name &amp; set it to mnuFileExit<br />21&gt; Locate the property Text &amp; set it to E&amp;xit</p>
<p>Now i am sure by now you should be able to create one more menu<br />22&gt; Create one more top level menu with Name mnuWindow and text &amp;Window<br />set its MDIList property to true(will show names of opened windows)<br />with 3 sub menus with name <br />mnuWindowCascade and text &amp;Cascade<br />mnuWindowTileVertical and text Tile&amp;Vertical<br />mnuWindowTileHorizontal and text Tile&amp;Horizontal</p>
<p>23&gt; Create one more top level menu with Name mnuHelp and text &amp;Help<br />with a sub menu with name mnuHelpAbout and text &amp;About&#8230;<br />&#39;&#8230;&#39; as the suffix is just a Microsoft convention to signify that the command will show a dialog box.</p>
<p>Putting life in the menus created by adding code to it<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>1&gt; Now in the frmSChild code add the following lines<br /> private static frmSChild m_SChildform;<br /> public static frmSChild GetChildInstance()<br /> {<br /> if (m_SChildform ==null) //if not created yet, Create an instance<br /> m_SChildform = new frmSChild();<br /> return m_SChildform; //just created or created earlier.Return it<br /> }</p>
<p>//This is to make sure that when we Click on a &#39;New Single&#39; menu on Parent form twice <br />//it should not open two instance of the same child form</p>
<p>2&gt; Click View-&gt;Designer of frmMdiMain again<br />3&gt; Double click New Single Menu on MDI main form<br />add the following code</p>
<p>frmSChild objfrmSChild = frmSChild.GetChildInstance();<br />objfrmSChild.MdiParent = this;<br />objfrmSChild.Show();<br />objfrmSChild.BringToFront();</p>
<p>4&gt; Click View-&gt;Designer of frmMdiMain again<br />5&gt; Double click New Multi Menu on MDI main form<br />add the following code</p>
<p>frmMChild objfrmMChild = new frmMChild();<br />objfrmMChild.MdiParent = this;<br />objfrmMChild.Show();</p>
<p>6&gt; Double click CloseChild on MDI main form<br />add the following code<br />try<br />{<br /> if(this.ActiveMdiChild.Name ==&quot;frmMChild&quot;)<br /> {<br /> frmMChild objfrmMChild = (frmMChild)this.ActiveMdiChild;<br /> objfrmMChild.Close();<br /> }<br /> else<br /> {<br /> frmSChild objfrmSChild = (frmSChild)this.ActiveMdiChild;<br /> objfrmSChild.Close();<br /> }</p>
<p>}<br />catch<br />{<br />}</p>
<p>7&gt; Double click Exit on MDI main form<br />add the following code</p>
<p>Application.Exit(); </p>
<p>8&gt; Double click Cascade menu under Windows on MDI main form<br />add the following code</p>
<p>this.LayoutMdi(MdiLayout.Cascade);<br />9&gt; same way for tile Vertical add <br />this.LayoutMdi(MdiLayout.TileVertical);<br />81&gt; and for tile horizontal add<br />this.LayoutMdi(MdiLayout.TileHorizontal);</p>
<p>20&gt; Now finally double click About menu in Help to add<br />frmAbout objfrmAbout = new frmAbout();<br />objfrmAbout.ShowDialog();</p>
<p>21&gt; Press F5 to start with debugging or Ctrl+F5 to start w/o debugging</p>
<p>Njoi programming!!<br /></span>
<p><span class="smallblack">The author (Irfan Patel) is a Microsoft Certified Solution Developer with Bachelor of Computer Application as the academic qualification.He has worked extensively with COM and has been programming since 1998. He has also trained more than 200 students and has taught various languages,RDBMS &amp; platforms from C,C++ to VB with Oracle,Access &amp; MS SQLServerfrom Vbscript,Javascript to ASP.His expertise comes from various industries viz Jewellery, Shipping ,Automobile ,Radio Frequency Devices, Photometers to name few.Besides programming he loves music,singing,dancing, bike riding &amp; cricket.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/05/mdi-with-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Manager API</title>
		<link>http://www.csharphelp.com/2007/05/windows-manager-api/</link>
		<comments>http://www.csharphelp.com/2007/05/windows-manager-api/#comments</comments>
		<pubDate>Wed, 16 May 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Win Forms]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=545</guid>
		<description><![CDATA[The following is an API that is designed to manage power down, hibernate and stand by functionality on your PC. Download Source]]></description>
			<content:encoded><![CDATA[<p><span class="smallblack">The following is an API that is designed to manage power down, hibernate and stand by functionality on your PC.</span></p>
<p><span class="smallblack">Download <a href="http://www.csharphelp.com/archives3/files/archive564/WindowsManager.zip">Source</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/05/windows-manager-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing A Winform In C# And Linking It To A SQL Server Database</title>
		<link>http://www.csharphelp.com/2007/04/designing-a-winform-in-c-and-linking-it-to-a-sql-server-database/</link>
		<comments>http://www.csharphelp.com/2007/04/designing-a-winform-in-c-and-linking-it-to-a-sql-server-database/#comments</comments>
		<pubDate>Mon, 09 Apr 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Win Forms]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=508</guid>
		<description><![CDATA[The main objective of windows basedprogramming is to create applications that are linked to databases,have user-friendly interface (windows forms) and are capable of runningon most platforms. C# language has all these capabilities to createapplications that are mostly required by the programmers at the time ofdesigning the interface and coding the modules of their projects. SinceC# [...]]]></description>
			<content:encoded><![CDATA[<p><span class="smallblack">The main objective of windows basedprogramming is to create applications that are linked to databases,have user-friendly interface (windows forms) and are capable of runningon most platforms. C# language has all these capabilities to createapplications that are mostly required by the programmers at the time ofdesigning the interface and coding the modules of their projects. SinceC# is object oriented (where each entity is considered as object andwhere terminologies like abstraction, encapsulation, polymorphism, andinheritance prevails the language paradigm), most of the high levelprogrammers feels easy to code the program in the form of classes andto reuse them in their later code. </span></p>
<p><span class="smallblack">This article will teach you how to designan interface (Windows Form) in Visual Studio .NET using the language ofC# and then creating and linking it to a database on SQL Server 2000.The first thing to be done is to start the Visual Studio .NETenvironment and create a new Project named &quot;WindowsApplication1&quot;. Theprojects by default are usually saved in &quot;My Documents\Visual StudioProjects&quot; folder but you can browse and change the location. Nextchoose the Project Types as: Visual C# Projects and Templates: WindowsApplication and click OK. Now a new project for you has been created.You can add as many forms you like from the Project &#8212;&gt; Add WindowsForms, but here we need only two forms. The Form1 is designed throughthe Toolbox components as follows. The View &#8212;&gt; Toolbox containsWindows components like Labels, Text box, Combo box, Buttons, Radio andCheck box, Picture box, List box, Timer, Progress bar, Main Menu,DataGrid and other controls. You just need to drag these on the formand set their properties. All the code for the above additions will beautomatically generated by the .NET compiler. An example picture of theForm1 to be designed for this tutorial is shown below:</span></p>
<p><span class="smallblack"><img src="http://www.csharphelp.com/archives3/files/archive526/Image1.gif" height="486" width="482" alt="" /></span></p>
<p><span class="smallblack">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="text-decoration:underline;">Figure 1: FORM1 DESIGN</span></span></p>
<p><span class="smallblack">Form2 will only contain the DataGridComponent from the Toolbox. You can set the Color, Name, Font and otherproperties through the Properties of the forms. Here I have set theBackground color to Blue.</span></p>
<p><span class="smallblack">Now move towards designing the database.This database is a simple database for registering people to use anyemail service. Start the Enterprise Manager of the SQL Server 2000 andcreate new database named &quot;REGISTER DATABASE&quot;. Within the database,create new table named &quot;REGISTER&quot; in which following columns andattributes are defined while designing:</span></p>
<table border="1" cellpadding="7" cellspacing="1" width="443">
<tbody>
<tr>
<td valign="TOP" width="30%">
<p>COLUMN NAME</p>
</td>
<td valign="TOP" width="23%">
<p>DATA TYPE</p>
</td>
<td valign="TOP" width="18%">
<p>LENGTH</p>
</td>
<td valign="TOP" width="29%">
<p>ALLOW NULLS</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>ID</p>
</td>
<td valign="TOP" width="23%">
<p>int</p>
</td>
<td valign="TOP" width="18%">
<p>4</p>
</td>
<td valign="TOP" width="29%">
<p>No</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>FNAME</p>
</td>
<td valign="TOP" width="23%">
<p>varchar</p>
</td>
<td valign="TOP" width="18%">
<p>50</p>
</td>
<td valign="TOP" width="29%">
<p>No</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>LNAME</p>
</td>
<td valign="TOP" width="23%">
<p>varchar</p>
</td>
<td valign="TOP" width="18%">
<p>50</p>
</td>
<td valign="TOP" width="29%">
<p>No</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>LANG</p>
</td>
<td valign="TOP" width="23%">
<p>char</p>
</td>
<td valign="TOP" width="18%">
<p>30</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>COUNTRY</p>
</td>
<td valign="TOP" width="23%">
<p>char</p>
</td>
<td valign="TOP" width="18%">
<p>30</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>STATE</p>
</td>
<td valign="TOP" width="23%">
<p>char</p>
</td>
<td valign="TOP" width="18%">
<p>30</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>ZIPCODE</p>
</td>
<td valign="TOP" width="23%">
<p>int</p>
</td>
<td valign="TOP" width="18%">
<p>4</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>TIMEZONE</p>
</td>
<td valign="TOP" width="23%">
<p>char</p>
</td>
<td valign="TOP" width="18%">
<p>30</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>GENDER</p>
</td>
<td valign="TOP" width="23%">
<p>char</p>
</td>
<td valign="TOP" width="18%">
<p>30</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>BDAY</p>
</td>
<td valign="TOP" width="23%">
<p>int</p>
</td>
<td valign="TOP" width="18%">
<p>4</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>BMONTH</p>
</td>
<td valign="TOP" width="23%">
<p>char</p>
</td>
<td valign="TOP" width="18%">
<p>30</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>BYEAR</p>
</td>
<td valign="TOP" width="23%">
<p>int</p>
</td>
<td valign="TOP" width="18%">
<p>4</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="TOP" width="30%">
<p>OCCUPATION</p>
</td>
<td valign="TOP" width="23%">
<p>varchar</p>
</td>
<td valign="TOP" width="18%">
<p>50</p>
</td>
<td valign="TOP" width="29%">
<p>Yes</p>
</td>
</tr>
</tbody>
</table>
<p><span class="smallblack">Now the next step is to link this databasewith our Windows Application. Go back to Form1 and drag theSqlConnection and SqlDataAdapter components from theToolbox&#8212;-&gt;Data bar. Double click on the form to go the code. Thenamespaces at the above of your program should contain these:</span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">using</span><span style="font-family:Courier New;font-size:x-small;"> System;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">using</span><span style="font-family:Courier New;font-size:x-small;"> System.Drawing;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">using</span><span style="font-family:Courier New;font-size:x-small;"> System.Collections;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">using</span><span style="font-family:Courier New;font-size:x-small;"> System.ComponentModel;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">using</span><span style="font-family:Courier New;font-size:x-small;"> System.Windows.Forms;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">using</span><span style="font-family:Courier New;font-size:x-small;"> System.Data;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">using</span><span style="font-family:Courier New;font-size:x-small;"> System.Data.SqlClient;</span></span></p>
<p><span class="smallblack">Allthe SqlConnection, SqlCommand, SqlDataAdapter etc are inherited fromSystem.Data.SqlClient. Next create new variables for storing the valuesretrieved from the textboxes and combo boxes keyed in by the user whilefilling out the form. For example we declare the following:</span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">string</span><span style="font-family:Courier New;fon</p>
<p>t-size:x<br />
-small;"> Fname,Lname,Lang,Country,State,Timezone,</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">Bmonth,Byear,Occup;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">char</span><span style="font-family:Courier New;font-size:x-small;"> Gender;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">int</span><span style="font-family:Courier New;font-size:x-small;"> Zipcode,Bday;</span></span></p>
<p><span class="smallblack"></span></p>
<p><span class="smallblack">Then we retrieve all that is keyedin by the user by the component events. For every component i.e. textboxes, combo boxes and radio boxes that we created, write the followingcode:</span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">void</span><span style="font-family:Courier New;font-size:x-small;"> textBox1_TextChanged(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">object</span><span style="font-family:Courier New;font-size:x-small;"> sender, System.EventArgs e)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">{</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Fname=</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.textBox1.Text.ToString();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">}</span></span></p>
<p><span class="smallblack"></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">void</span><span style="font-family:Courier New;font-size:x-small;"> comboBox1_SelectedIndexChanged(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">object</span><span style="font-family:Courier New;font-size:x-small;"> sender, System.EventArgs e)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">{</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Lang=</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.comboBox1.SelectedItem.ToString();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">}</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;"></span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">void</span><span style="font-family:Courier New;font-size:x-small;"> radioButton1_CheckedChanged(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">object</span><span style="font-family:Courier New;font-size:x-small;"> sender, System.EventArgs e)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">{</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Gender=&#39;M&#39;;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">}</span></span></p>
<p><span class="smallblack">Now add the following code to make the buttons functional in their click event code:</span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;"></span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">void</span><span style="font-family:Courier New;font-size:x-small;"> button1_Click(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">object</span><span style="font-family:Courier New;font-size:x-small;"> sender, System.EventArgs e)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">{				//LIST ALL REGISTERIES BUTTON</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	Form2 f2=</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">new</span><span style="font-family:Courier New;font-size:x-small;"> Form2();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	f2.ShowDialog();	</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">}</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">void</span><span style="font-family:Courier New;font-size:x-small;"> button2_Click(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">object</span><span style="font-family:Courier New;font-size:x-small;"> sender, System.EventArgs e)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">{				//CANCEL BUTTON</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Dispose();	</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">}</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">void</span><span style="font-family:Courier New;font-size:x-small;"> button3_Click(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">object</span><span style="font-family:Courier New;font-size:x-small;"> sender, System.EventArgs e)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">{				//REGISTER NOW BUTTON</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;"></span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">if</span><span style="font-family:Courier New;font-size:x-small;">(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.textBox1.Text==&quot;&quot;||</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.textBox2.Text==&quot;&quot;)</span></span></p>
<p><span clas</p>
<p>s="smallblack"><span style="font-family:Courier New;font-size:x-small;">		MessageBox.Show(&quot;Please enter your name&quot;);</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">else</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	{</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.sqlConnection1.Open();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">		</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">string</span><span style="font-family:Courier New;font-size:x-small;">insert=&quot;INSERT INTO REGISTER(FNAME, LNAME, LANG, COUNTRY, STATE,ZIPCODE, TIMEZONE, GENDER, BDAY, BMONTH, BYEAR, OCCUPATION) VALUES (&#39;&quot;+</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Fname +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Lname +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Lang +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Country +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.State +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Zipcode +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Timezone +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Gender +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Bday +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Bmonth +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Byear +&quot;&#39;,&#39;&quot;+ </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.Occup +&quot;&#39;)&quot;;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">SqlCommand cmd=</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">new</span><span style="font-family:Courier New;font-size:x-small;"> SqlCommand(insert,</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.sqlConnection1);</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">cmd.ExecuteNonQuery();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">			</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">		</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.sqlConnection1.Close();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">		MessageBox.Show(&quot;You have been successfully registered to our database.&quot;);</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	}</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">}</span></span></p>
<p><span class="smallblack"></span></p>
<p><span class="smallblack">Now we go to the Form2. We havealready set a DataGrid in the form. Also drag the SqlConnection andSqlDataAdapter components same as before and add the following code inthe Form2_Load event method:</span></p>
<p><span class="smallblack"><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">private</span><span style="font-family:Courier New;font-size:x-small;"> </span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">void</span><span style="font-family:Courier New;font-size:x-small;"> Form2_Load(</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">object</span><span style="font-family:Courier New;font-size:x-small;"> sender, System.EventArgs e)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">{		</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">string</span><span style="font-family:Courier New;font-size:x-small;"> select=&quot;SELECT * FROM REGISTER&quot;;</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	DataSet ds=</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">new</span><span style="font-family:Courier New;font-size:x-small;"> DataSet();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.sqlConnection1.Open();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.sqlDataAdapter1=</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">new</span><span style="font-family:Courier New;font-size:x-small;"> SqlDataAdapter(select,sqlConnection1);</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.sqlDataAdapter1.Fill(ds,&quot;REGISTER&quot;);</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">if</span><span style="font-family:Courier New;font-size:x-small;">(ds.Tables[&quot;REGISTER&quot;].Rows.Count==0)</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	{</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	MessageBox.Show(&quot;There are currently no registries in the database.&quot;);</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	}</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">else</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	{</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">		</span><span style="font-f</p>
<p>amily:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.dataGrid1.SetDataBinding(ds,&quot;REGISTER&quot;);</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	}</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">	</span><span style="font-family:Courier New;color:#0000ff;font-size:x-small;">this</span><span style="font-family:Courier New;font-size:x-small;">.sqlConnection1.Close();</span></span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;">}</span></span></p>
<p><span class="smallblack">The form2 after running the program and registering a user &quot;Fatima Ahmed&quot; will look like this:</span></p>
<p><span class="smallblack"><span style="font-family:Courier New;font-size:x-small;"></span></span></p>
<p><span class="smallblack"><img src="http://www.csharphelp.com/archives3/files/archive526/Image2.gif" height="166" width="758" alt="" /></span></p>
<p><span class="smallblack">Hope this article helps you learn all what is taught about creating, designing a Winform in C# and linking it to a database.</span></p>
<p>&lt;!&#8211; start a block of source code &#8211;&gt;<br />
<h3><span class="smallblack">Downloads</span></h3>
<p>&lt;!&#8211; demo and source files &#8211;&gt;
<p><span class="smallblack"><a href="http://www.csharphelp.com/archives3/files/archive526/Winform.zip">Download demo project &#8211; 138 KB</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/04/designing-a-winform-in-c-and-linking-it-to-a-sql-server-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RssNewsFeed &#8211; Access Rss Feeds Easily From Your C# Applciations</title>
		<link>http://www.csharphelp.com/2007/03/rssnewsfeed-access-rss-feeds-easily-from-your-c-applciations/</link>
		<comments>http://www.csharphelp.com/2007/03/rssnewsfeed-access-rss-feeds-easily-from-your-c-applciations/#comments</comments>
		<pubDate>Sat, 31 Mar 2007 04:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[Win Forms]]></category>

		<guid isPermaLink="false">http://www.csharphelp.com.php5-3.dfw1-2.websitetestlink.com/?p=499</guid>
		<description><![CDATA[Introduction RssNewsFeed is a free .NET library written in C#, which allows you to access an rss&#160; feed without going through the hassle of parsing. It will&#160;&#160;extract feed information, together with the news items, and return them as a collection of objects. (RSS is a Web content syndication format&#160;and is an acronym for Really SimpleSyndication. [...]]]></description>
			<content:encoded><![CDATA[<h3><span class="smallblack">Introduction</span></h3>
<p><span class="smallblack">RssNewsFeed is a free .NET library written in C#, which allows you to access an rss&nbsp; feed without going through the hassle of parsing. It will&nbsp;&nbsp;extract feed information, together with the news items, and return them as a collection of objects.</span></p>
<p><span class="smallblack">(RSS is a Web content syndication format&nbsp;and is an acronym for <i><b>R</b>eally <b>S</b>imple<b>S</b>yndication. </i>RSS is a dialect of XML and so all RSS files must conform to the XML 1.0, as published on the World Wide Web Consortium (W3C) website).</span></p>
<h3><span class="smallblack">Using the library</span></h3>
<p><span class="smallblack">The RssNewsFeed consists of three public classes, <strong>ContentSyndication, SyndicationChannel, </strong>and <strong>SyndicationItem.</strong>&nbsp;A <strong>SyndicationChannel</strong> &nbsp;object is returned by the <strong>ContentSyndication</strong>class when the <em>GetContent</em> () method is returned, and contains information about the requested channel. It also contains a&nbsp;collection of <strong>SyndicationItem</strong> objects which contain information about each news item.</span></p>
<p><span class="smallblack">To use the library in your application, insert a referenece to the <strong><em>RssNewsFeed.dll</em></strong>by right-clicking on the Reference tree node in the Visual Studio IDE. Select <em>Add Reference, </em>and then select <em>Browse</em>. After you&#39;ve located the dll, select <em>Ok.</em></span></p>
<p><span class="smallblack">Insert&nbsp;the&nbsp;namespace Cyberise.RssNewsFeed in your application, and create an instance of the <strong>ContentSyndication</strong> class. See the sample code for more information.</span></p>
<p><span class="smallblack">The RSSNewsFeed has its own exception class NewsFeedException, which is thrown in the event of an error. A descriptive message together with the actual exception which caused the error&nbsp;are passed off to the calling application. These can be accessed via the <em>Message</em>() and <em>InnerExecption</em>() methods respectively.</span></p>
<h3><span class="smallblack">Features</span></h3>
<ul><span class="smallblack">
<li>Parses rss versions 0.9,0.91,1.0, and 2.0</li>
<li>Returns&nbsp;feed&#39;s logo&nbsp;website as bitmap object.</li>
<li>Free for commerical and personal use.</li>
<p></span></ul>
<h3><span class="smallblack">Documentation</span></h3>
<p><span class="smallblack">Latest html documentation on how to use the assembly&nbsp;is available from&nbsp; <a target="_new" href="http://www.cyberise.sytes.net/Products/RssNewsFeed/Documentation/">here</a>. A compiled help file is also <a target="_new" href="http://www.cyberise.sytes.net/Products/RssNewsFeed/Documentation/RssNewsFeed.chm">available</a>.<br /></span></p>
<h3><span class="smallblack">Download</span></h3>
<p><span class="smallblack">The latest version of RssNewsFeed can be accessed from <a target="_new" href="http://www.cyberise.sytes.net/Products/RssNewsFeed/RssNewsFeed.zip">here</a>. Sample demo code on how to use the assembly library is also included in the zip file. The library was compiled using the&nbsp;.NET 1.0 framework.</span></p>
<h3><span class="smallblack">Contact</span></h3>
<p><span class="smallblack">If you would like to contact me for queries, comments,&nbsp;or to report a bug, please click <a target="_new" href="http://www.cyberise.sytes.net/html/contact.aspx">here</a>. Although the library is free for commercial or personal use, I would appreciate a link to this <a target="_new" href="http://www.cyberise.sytes.net/html/rssnewsfeed.aspx">page</a>placed on your site&nbsp;and&nbsp;please send me an email so that I&nbsp;can add a link to your application from my site and build up a list of applications&nbsp;using the library.</span></p>
<h3><span class="smallblack">Version history</span></h3>
<p><span class="smallblack">1.0 Initial version<br />1.1 Rewrote xml parser to handle incorrectly formed rss news feeds. Released for public use.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csharphelp.com/2007/03/rssnewsfeed-access-rss-feeds-easily-from-your-c-applciations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

