<?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>Helping Online Entrepreneurs &#187; C#</title>
	<atom:link href="http://www.codeitwell.com/category/csharp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codeitwell.com</link>
	<description>With Resources on How to Make Money Online doing Freelancing, Affiliate Marketing, Blogging and many more ...</description>
	<lastBuildDate>Wed, 09 Feb 2011 11:39:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How some of the programming languages are named</title>
		<link>http://www.codeitwell.com/how-some-of-the-programming-languages-are-named.html</link>
		<comments>http://www.codeitwell.com/how-some-of-the-programming-languages-are-named.html#comments</comments>
		<pubDate>Sun, 24 Aug 2008 12:22:05 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=42</guid>
		<description><![CDATA[PHP has come a long way in the last few years and now its one of the most popular known web language but has any one of us thought why the Name of the language is PHP and nothing else Or what is the full form of PHP. If No read through the complete post [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/safe-programming.html' rel='bookmark' title='Permanent Link: Safe Programming'>Safe Programming</a></li>
<li><a href='http://www.codeitwell.com/increment-and-decrement-operators.html' rel='bookmark' title='Permanent Link: Increment and Decrement Operators'>Increment and Decrement Operators</a></li>
<li><a href='http://www.codeitwell.com/working-with-asp.html' rel='bookmark' title='Permanent Link: Working with ASP'>Working with ASP</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>PHP has come a long way in the last few years and now its one of the most popular known web language but has any one of us thought why the Name of the language is PHP and nothing else Or what is the full form of PHP. If No read through the complete post here.</p>
<p>I don't know why but the first question that comes to my mind when I start on it is why the programming language name is what it is. </p>
<h3>C</h3>
<p>When I started on C the same question came to my mind and the answer this is what I found Dennis Ritchie of Bell Labs created the C Programming Language in 1971-1972 and at that time there were couple of languages like A and B before C language came into existence and so he named the awesome language as <strong>C</strong>.</p>
<h3>C++</h3>
<p>The same question came to mind when I started my quest to learn C++ and probably I found the answer too many times in each book of C++ and so I would not add much detail here. C++ was written by  Bjarne Stroustrup  at Bell Labs during 1983-1985. C++ is an extension of C and so was named with the postfix operator of C to give it one step forward then C.</p>
<h3>C#</h3>
<p>Couple of years back again the same question came for C# when I started on C# and .NET and the answer I found is # can be broken into ++++ and so its names as #. So now we can understand that C# is an extension of C++ but without backward compatibility with the same compiler.</p>
<h3>PHP</h3>
<p>Now the same question with PHP. Ohhh, too many questions haaan? But I found this answer the most interesting. </p>
<p>PHP was originally created Rasmus Lerdorf in 1995, and was just collection of some Perl scripts and library of C programs for tracking accesses to his online resume. Thus was born the first version of PHP. He named this set of scripts '<strong>P</strong>ersonal <strong>H</strong>ome <strong>P</strong>age Tools'. He confesses that he created PHP purely to serve his own interest, to solve his own set of problems. He made the source publicly available so others could benefit from it. That set the ball rolling.</p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/safe-programming.html' rel='bookmark' title='Permanent Link: Safe Programming'>Safe Programming</a></li>
<li><a href='http://www.codeitwell.com/increment-and-decrement-operators.html' rel='bookmark' title='Permanent Link: Increment and Decrement Operators'>Increment and Decrement Operators</a></li>
<li><a href='http://www.codeitwell.com/working-with-asp.html' rel='bookmark' title='Permanent Link: Working with ASP'>Working with ASP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/how-some-of-the-programming-languages-are-named.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Read From File Using StreamReader Class</title>
		<link>http://www.codeitwell.com/read-from-file-using-streamreader-class.html</link>
		<comments>http://www.codeitwell.com/read-from-file-using-streamreader-class.html#comments</comments>
		<pubDate>Mon, 26 May 2008 15:19:10 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=31</guid>
		<description><![CDATA[In this post we explained how to write text to a file in C#. Today we will explain reading text from a file using the StreamReader class. So create a file "text.txt" in the same directory where is the executable of the project. We will create a C# Console Application. First, we must include this [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/read-from-file-in-cpp.html' rel='bookmark' title='Permanent Link: Read From File In C++'>Read From File In C++</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
<li><a href='http://www.codeitwell.com/using-the-timer-class.html' rel='bookmark' title='Permanent Link: Using the Timer Class'>Using the Timer Class</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>In <a href="http://www.codeitwell.com/write-to-file-in-cs.html">this</a> post we explained how to write text to a file in C#. Today we will explain reading text from a file using the StreamReader class.<br />
So create a file "text.txt" in the same directory where is the executable of the project. We will create a C# Console Application.<br />
First, we must include this namespace, to use the StreamReader class</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">IO</span>;</pre>
<p>Then write this code in the place where you want your program to read the file</p>
<pre class="csharp">StreamReader sr = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamReader<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;text.txt&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #FF0000;">string</span> line;
&nbsp;
<span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>line = sr.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>line<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>With this code we read the text written in the file "text.txt" line by line, and print it on the console.<br />
Simple as that.</p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/read-from-file-in-cpp.html' rel='bookmark' title='Permanent Link: Read From File In C++'>Read From File In C++</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
<li><a href='http://www.codeitwell.com/using-the-timer-class.html' rel='bookmark' title='Permanent Link: Using the Timer Class'>Using the Timer Class</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/read-from-file-using-streamreader-class.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using the Timer Class</title>
		<link>http://www.codeitwell.com/using-the-timer-class.html</link>
		<comments>http://www.codeitwell.com/using-the-timer-class.html#comments</comments>
		<pubDate>Thu, 22 May 2008 21:12:38 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=30</guid>
		<description><![CDATA[The timer class is often used in many applications. It's very simple for using, like all the classes implemented in .Net Framework. So create a C# Console project, we will try this class in a console application. Include this namespace, so we can use the Timer class using System.Timers; Then in the Main() function put [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/read-from-file-using-streamreader-class.html' rel='bookmark' title='Permanent Link: Read From File Using StreamReader Class'>Read From File Using StreamReader Class</a></li>
<li><a href='http://www.codeitwell.com/usage-of-registrykey-class.html' rel='bookmark' title='Permanent Link: Usage Of RegistryKey Class'>Usage Of RegistryKey Class</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>The timer class is often used in many applications. It's very simple for using, like all the classes implemented in .Net Framework.</p>
<p>So create a C# Console project, we will try this class in a console application.</p>
<p>Include this namespace, so we can use the Timer class</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Timers</span>;</pre>
<p>Then in the Main() function put this code</p>
<pre class="csharp">Timer tm = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Timer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
tm.<span style="color: #0000FF;">Interval</span> = <span style="color: #FF0000;">1000</span>;
tm.<span style="color: #0000FF;">Elapsed</span> += <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ElapsedEventHandler<span style="color: #000000;">&#40;</span>tm_Elapsed<span style="color: #000000;">&#41;</span>;
tm.<span style="color: #0000FF;">Enabled</span> = <span style="color: #0600FF;">true</span>;
&nbsp;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;To exit hit the <span style="color: #008080; font-weight: bold;">\&quot;</span>Enter<span style="color: #008080; font-weight: bold;">\&quot;</span> key.&quot;</span><span style="color: #000000;">&#41;</span>;
Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>In the above code we are creating an object from the Timer class, set his interval so 1000 miliseconds, create an event which will be invoked every 1000 miliseconds and enable the timer.<br />
Then we write some text to the console, just for information for the user how to exit from the application. And the last line stops the program to end, and waits for user input.</p>
<p>Below the main function create this event</p>
<pre class="csharp"><span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> tm_Elapsed<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, ElapsedEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>DateTime.<span style="color: #0000FF;">Now</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre>
<p>In the end you can exclude the unused usings, showed in <a title="Remove the unused usings" href="http://www.codeitwell.com/remove-unused-using-statements.html">this</a> post.</p>
<p>Now start the application, it will write on the console the actual time every second. Press Enter to exit.</p>
<p>You can put diferrent code in the tm_Elapsed function, so that code will execute every second or the interval you will set.</p>
<p>Download the project from <a title="Timer Example" href="http://www.codeitwell.com/wp-content/downloads/TimerExample.rar">here</a>.</p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/read-from-file-using-streamreader-class.html' rel='bookmark' title='Permanent Link: Read From File Using StreamReader Class'>Read From File Using StreamReader Class</a></li>
<li><a href='http://www.codeitwell.com/usage-of-registrykey-class.html' rel='bookmark' title='Permanent Link: Usage Of RegistryKey Class'>Usage Of RegistryKey Class</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/using-the-timer-class.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Items to ListView Control</title>
		<link>http://www.codeitwell.com/adding-items-to-listview-control.html</link>
		<comments>http://www.codeitwell.com/adding-items-to-listview-control.html#comments</comments>
		<pubDate>Thu, 15 May 2008 15:08:59 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=28</guid>
		<description><![CDATA[Adding items to list view is more difficult than adding items to list box. And in general the ListView control is more complex than the ListBox, and that makes it more difficult to work with. So, in a C# project, create this form The controls have the default names in Visual Studio 2008. Than click [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/adding-items-to-listbox-and-combobox-controls.html' rel='bookmark' title='Permanent Link: Adding Items to ListBox and ComboBox Controls'>Adding Items to ListBox and ComboBox Controls</a></li>
<li><a href='http://www.codeitwell.com/readwrite-registry-keys.html' rel='bookmark' title='Permanent Link: Read/Write Registry Keys'>Read/Write Registry Keys</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>Adding items to list view is more difficult than adding items to list box. And in general the ListView control is more complex than the ListBox, and that makes it more difficult to work with.</p>
<p>So, in a C# project, create this form</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/28.1.gif" alt="ListView form" width="316" height="337" /></p>
<p style="text-align: left;">The controls have the default names in Visual Studio 2008.</p>
<p style="text-align: left;">
<p style="text-align: left;">Than click on the little button in the top right corner of the ListView</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/28.2.gif" alt="ListView properties" width="490" height="277" /></p>
<p style="text-align: left;">Than from the options of the View dropdown menu select Details. Now, click on the Edit Columns link and create two columns</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/28.3.gif" alt="" /></p>
<p>You can optimize the column width.</p>
<p style="text-align: left;">Now, in the button1 click event write this code</p>
<p style="text-align: left;">
<pre class="csharp"><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>str=<span style="color: #000000;">&#123;</span>textBox1.<span style="color: #0000FF;">Text</span>, textBox2.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#125;</span>;
ListViewItem lvItem = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ListViewItem<span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span>;
listView1.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>lvItem<span style="color: #000000;">&#41;</span>;</pre>
<p>We are creating a string that contains the text written in the text boxes, and it will be inserted in the list view control. Then we create a ListViewItem object and assign the values to it, and in the end we insert the ListViewItem object in the listView1 control.</p>
<p>Run the application and write something ni the text boxes, then click the button. The values will be entered in the list view control.</p>
<p><a href="http://www.codeitwell.com/wp-content/downloads/ListView.rar">Download the project</a></p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/adding-items-to-listbox-and-combobox-controls.html' rel='bookmark' title='Permanent Link: Adding Items to ListBox and ComboBox Controls'>Adding Items to ListBox and ComboBox Controls</a></li>
<li><a href='http://www.codeitwell.com/readwrite-registry-keys.html' rel='bookmark' title='Permanent Link: Read/Write Registry Keys'>Read/Write Registry Keys</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/adding-items-to-listview-control.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove Unused Using Statements</title>
		<link>http://www.codeitwell.com/remove-unused-using-statements.html</link>
		<comments>http://www.codeitwell.com/remove-unused-using-statements.html#comments</comments>
		<pubDate>Mon, 12 May 2008 20:00:35 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=27</guid>
		<description><![CDATA[When we create a new C#.Net project (or other .Net project, , the editor includes the following using statements in the code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; But most of this included namespaces are unused, and you don't know which of them you don't [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/using-the-timer-class.html' rel='bookmark' title='Permanent Link: Using the Timer Class'>Using the Timer Class</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>When we create a new C#.Net project (or other .Net project, , the editor includes the following using statements in the code</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Collections</span>.<span style="color: #0000FF;">Generic</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">ComponentModel</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Data</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Drawing</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Linq</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Text</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Forms</span>;</pre>
<p>But most of this included namespaces are unused, and you don't know which of them you don't need.<br />
So, in Visual Studio 2008 there is a new feature for excluding the unused usings from your project.<br />
In the code editor, click the right mouse button and in the context menu go to Organize Usings -> Remove and Sort</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/27.1.gif" alt="Remove unused usings"/></p>
<p>If you have not written additional code, the editor will leave this two using statements</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Forms</span>;</pre>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/using-the-timer-class.html' rel='bookmark' title='Permanent Link: Using the Timer Class'>Using the Timer Class</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/remove-unused-using-statements.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Items to ListBox and ComboBox Controls</title>
		<link>http://www.codeitwell.com/adding-items-to-listbox-and-combobox-controls.html</link>
		<comments>http://www.codeitwell.com/adding-items-to-listbox-and-combobox-controls.html#comments</comments>
		<pubDate>Sat, 10 May 2008 20:57:55 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=25</guid>
		<description><![CDATA[Adding items to this controls in .Net is very easy. To demonstrate that we will create a simple project with the following controls: ListBox (name: listBox1) ComboBox (name: comboBox1) TextBox (name: textBox1) Button (text: Add) So, drag this controls from the toolbox and drop them on the main form one by one. Make a form [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/adding-items-to-listview-control.html' rel='bookmark' title='Permanent Link: Adding Items to ListView Control'>Adding Items to ListView Control</a></li>
<li><a href='http://www.codeitwell.com/aspnet-web-site-sample.html' rel='bookmark' title='Permanent Link: ASP.Net Web Site Sample'>ASP.Net Web Site Sample</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>Adding items to this controls in .Net is very easy. To demonstrate that we will create a simple project with the following controls:</p>
<ul>
<li>ListBox (name: listBox1)</li>
<li>ComboBox (name: comboBox1)</li>
<li>TextBox (name: textBox1)</li>
<li>Button (text: Add)</li>
</ul>
<p>So, drag this controls from the toolbox and drop them on the main form one by one. Make a form like this</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/25.1.gif" alt="List box and combo box" width="277" height="216" /></p>
<p style="text-align: left;">Now double click on the button, it will create a button click event. Insert this code there</p>
<p style="text-align: left;">
<pre class="csharp">listBox1.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>textBox1.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span>;
comboBox1.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>textBox1.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span>;
textBox1.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>Now, write something in the text box and then click the button. The text you entered in the textBox1 will be inserted as item in the listBox1 and comboBox1, and the textBox1 text will be cleared.</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/25.2.gif" alt="List box and combo box with data" width="277" height="216" /></p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/adding-items-to-listview-control.html' rel='bookmark' title='Permanent Link: Adding Items to ListView Control'>Adding Items to ListView Control</a></li>
<li><a href='http://www.codeitwell.com/aspnet-web-site-sample.html' rel='bookmark' title='Permanent Link: ASP.Net Web Site Sample'>ASP.Net Web Site Sample</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/adding-items-to-listbox-and-combobox-controls.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usage Of RegistryKey Class</title>
		<link>http://www.codeitwell.com/usage-of-registrykey-class.html</link>
		<comments>http://www.codeitwell.com/usage-of-registrykey-class.html#comments</comments>
		<pubDate>Thu, 08 May 2008 16:09:57 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=23</guid>
		<description><![CDATA[The usage of RegistryKey class is very huge in many applications in which is needed to "remember" some settings of the application, and then load them when starting the application. Today we will use the RegistryKey class for that issue. The application will save this informations in the registry when exiting: Left Top Height Width [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/readwrite-registry-keys.html' rel='bookmark' title='Permanent Link: Read/Write Registry Keys'>Read/Write Registry Keys</a></li>
<li><a href='http://www.codeitwell.com/using-the-timer-class.html' rel='bookmark' title='Permanent Link: Using the Timer Class'>Using the Timer Class</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-using-streamreader-class.html' rel='bookmark' title='Permanent Link: Read From File Using StreamReader Class'>Read From File Using StreamReader Class</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>The usage of RegistryKey class is very huge in many applications in which is needed to "remember" some settings of the application, and then load them when starting the application.<br />
Today we will use the RegistryKey class for that issue. The application will save this informations in the registry when exiting:</p>
<ul>
<li>Left</li>
<li>Top</li>
<li>Height</li>
<li>Width</li>
<li>FirstStart</li>
</ul>
<p>And on start the application will load them.</p>
<p>Don't forget do add this code everywhere where you are using the RegistryKey class (see more <a href="http://www.codeitwell.com/readwrite-registry-keys.html">here</a>)</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">Microsoft.<span style="color: #0000FF;">Win32</span></span>;</pre>
<p>So, create a C# Windows Forms Application, and make a double click on the form it will create the Form1_Load event, it is executed when application starts.</p>
<p>Then, in the Form1_Load event paste this code</p>
<pre class="csharp">RegistryKey key = Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Software&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>.
<span style="color: #0000FF;">CreateSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Registry Test&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>key.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;FirstStart&quot;</span><span style="color: #000000;">&#41;</span> == <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
    MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;The application is started for the first time.<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span>+
                    <span style="color: #808080;">&quot;I will not load the settings.&quot;</span>, <span style="color: #808080;">&quot;Info&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">else</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Left</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>key.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Left&quot;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Top</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>key.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Top&quot;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Height</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>key.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Height&quot;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Width</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>key.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Width&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
key.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>With the above code we create an object from the RegistryKey class and create a sub key "Registry Test" in the HKEY_CURRENT_USER/Software key. Then we check if the application is started for the first time. If the "FirstStart" value does not exist then the application is started for the first time, and that means that the other values ("Left", "Top", "Height", "Width") are not saved, and when the program tries to load them it will fall.<br />
So what we do, if the application is started for the first time, we do not load them, and popup a message to tell the user that. When loading the setting the value is casted to integer and then assigned to the appositely property. And then we close the key object.</p>
<p>Now go to solution explorer and open the Form1.Designer.cs file.</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/23.1.gif" alt="Form Designer class=" /></p>
<p>You will see the Dispose function there, so in that function above this code</p>
<pre class="csharp"><span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span>disposing<span style="color: #000000;">&#41;</span>;</pre>
<p>write the following code</p>
<pre class="csharp">RegistryKey key = Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Software&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>.
<span style="color: #0000FF;">CreateSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Registry Test&quot;</span><span style="color: #000000;">&#41;</span>;
key.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;FirstStart&quot;</span>, <span style="color: #FF0000;">0</span>, RegistryValueKind.<span style="color: #0000FF;">DWord</span><span style="color: #000000;">&#41;</span>;
key.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Left&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Left</span>, RegistryValueKind.<span style="color: #0000FF;">DWord</span><span style="color: #000000;">&#41;</span>;
key.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Top&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Top</span>, RegistryValueKind.<span style="color: #0000FF;">DWord</span><span style="color: #000000;">&#41;</span>;
key.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Height&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Height</span>, RegistryValueKind.<span style="color: #0000FF;">DWord</span><span style="color: #000000;">&#41;</span>;
key.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Width&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Width</span>, RegistryValueKind.<span style="color: #0000FF;">DWord</span><span style="color: #000000;">&#41;</span>;
key.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>This piece of code is called when we close the application, it saves the current values of the properties (Left, Top, Height, Width) and to value FirstStart assigns 0.</p>
<p>Build the application and start it. For the first time, it will popup a message box. Then move the application somewhere on your desktop, change its size and then close it, and the values will be recorded in the registry. The next time you start the application it will be on the same place you exited and its size will be the same.</p>
<p><a href="http://www.codeitwell.com/wp-content/downloads/UseOfRegistry.rar">Download the project</a></p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/readwrite-registry-keys.html' rel='bookmark' title='Permanent Link: Read/Write Registry Keys'>Read/Write Registry Keys</a></li>
<li><a href='http://www.codeitwell.com/using-the-timer-class.html' rel='bookmark' title='Permanent Link: Using the Timer Class'>Using the Timer Class</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-using-streamreader-class.html' rel='bookmark' title='Permanent Link: Read From File Using StreamReader Class'>Read From File Using StreamReader Class</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/usage-of-registrykey-class.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Read/Write Registry Keys</title>
		<link>http://www.codeitwell.com/readwrite-registry-keys.html</link>
		<comments>http://www.codeitwell.com/readwrite-registry-keys.html#comments</comments>
		<pubDate>Mon, 05 May 2008 19:25:26 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=21</guid>
		<description><![CDATA[Writing and reading to/from a registry key in .Net is really easy. All that is implemented in Microsoft.Win32 namespace, so at the start put this in the usings using Microsoft.Win32; Than in some function write this RegistryKey key = Registry.CurrentUser.OpenSubKey&#40;&#34;Software&#34;, true&#41; .CreateSubKey&#40;&#34;CodeItWell.com&#34;&#41;; So, we are creating an object from the RegistryKey class, the object will [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/usage-of-registrykey-class.html' rel='bookmark' title='Permanent Link: Usage Of RegistryKey Class'>Usage Of RegistryKey Class</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-in-cpp.html' rel='bookmark' title='Permanent Link: Read From File In C++'>Read From File In C++</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>Writing and reading to/from a registry key in .Net is really easy. All that is implemented in Microsoft.Win32 namespace, so at the start put this in the usings</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">Microsoft.<span style="color: #0000FF;">Win32</span></span>;</pre>
<p>Than in some function write this</p>
<pre class="csharp">RegistryKey key = Registry.<span style="color: #0000FF;">CurrentUser</span>.<span style="color: #0000FF;">OpenSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Software&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>
.<span style="color: #0000FF;">CreateSubKey</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;CodeItWell.com&quot;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>So, we are creating an object from the RegistryKey class, the object will open the sub key Software in HKEY_CURRENT_USER, and it will create a key there with the name CodeItWell.com.</p>
<p>Now lets create some values in that key</p>
<pre class="csharp">key.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;URL&quot;</span>, <span style="color: #808080;">&quot;http://www.codeitwell.com&quot;</span><span style="color: #000000;">&#41;</span>;
key.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Number&quot;</span>, <span style="color: #FF0000;">1234</span>, RegistryValueKind.<span style="color: #0000FF;">DWord</span><span style="color: #000000;">&#41;</span>;</pre>
<p>Here we create a string value URL with data http://www.codeitwell.com, and a DWORD value with its value 1234.</p>
<p>You can set many value kinds... see the picture below</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/21.1.gif" alt="Registry Value Kinds" width="476" height="142" /></p>
<p>Now open the registry editor Start -> Run -> Write "regedit" -> OK. Go to this path HKEY_CURRENT_USER\Software\CodeItWell.com, you will see the values on the right panel</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/21.2.gif" alt="Registry Editor" width="480" height="64" /></p>
<p>To read the registry values we will use the same object, see this</p>
<pre class="csharp">MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span>key.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;URL&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;URL&quot;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>You will get a message box showing the data in URL value. Try to change that data manually in the registry editor, and then call the event where the above line of code is entered and you will see the data will be changed.</p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/usage-of-registrykey-class.html' rel='bookmark' title='Permanent Link: Usage Of RegistryKey Class'>Usage Of RegistryKey Class</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-in-cpp.html' rel='bookmark' title='Permanent Link: Read From File In C++'>Read From File In C++</a></li>
<li><a href='http://www.codeitwell.com/write-to-file-in-cs.html' rel='bookmark' title='Permanent Link: Write To File in C#'>Write To File in C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/readwrite-registry-keys.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Data Entry In Microsoft Access Database</title>
		<link>http://www.codeitwell.com/simple-data-entry-in-microsoft-access-database.html</link>
		<comments>http://www.codeitwell.com/simple-data-entry-in-microsoft-access-database.html#comments</comments>
		<pubDate>Thu, 01 May 2008 22:01:15 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=17</guid>
		<description><![CDATA[In the previous post. We described the connection to the Microsoft Access database. Now we will add some functionality to that. The user can insert diferent records. For start, make a form like this (the names of the components are specified on the picture) Now in the button1 event method insert this code string connStr [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/creating-a-database-connection.html' rel='bookmark' title='Permanent Link: Creating a Database Connection'>Creating a Database Connection</a></li>
<li><a href='http://www.codeitwell.com/aspnet-database-connection.html' rel='bookmark' title='Permanent Link: ASP.Net Database Connection'>ASP.Net Database Connection</a></li>
<li><a href='http://www.codeitwell.com/adding-items-to-listview-control.html' rel='bookmark' title='Permanent Link: Adding Items to ListView Control'>Adding Items to ListView Control</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p style="text-align: left;">In the previous <a title="Creating Database Connection" href="http://www.codeitwell.com/creating-a-database-connection.html">post</a>. We described the connection to the Microsoft Access database.</p>
<p>Now we will add some functionality to that. The user can insert diferent records.</p>
<p>For start, make a form like this (the names of the components are specified on the picture)</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/17.1.gif" alt="Data entry" width="280" height="200" /></p>
<p>Now in the button1 event method insert this code</p>
<p style="text-align: left;">
<pre class="csharp"><span style="color: #FF0000;">string</span> connStr = <span style="color: #808080;">&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;&quot;</span>;
OleDbConnection conn = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OleDbConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
conn.<span style="color: #0000FF;">ConnectionString</span> = connStr;
<span style="color: #FF0000;">string</span> cmdStr = <span style="color: #808080;">&quot;INSERT INTO Info (FirstName, LastName)&quot;</span> +
<span style="color: #808080;">&quot; VALUES('&quot;</span>+textBox1.<span style="color: #0000FF;">Text</span>+<span style="color: #808080;">&quot;', '&quot;</span>+textBox2.<span style="color: #0000FF;">Text</span>+<span style="color: #808080;">&quot;');&quot;</span>;
OleDbCommand cmd = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OleDbCommand<span style="color: #000000;">&#40;</span>cmdStr, conn<span style="color: #000000;">&#41;</span>;
conn.<span style="color: #0000FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
cmd.<span style="color: #0000FF;">ExecuteNonQuery</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
conn.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>The code is the same from the previous post with only one difference, the string cmdStr is changed. Now the command in the table columns will insert the data which is written in the text boxes.</p>
<p>Now the table will have different records</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/17.2.gif" alt="Data entry table" width="319" height="297" /></p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/creating-a-database-connection.html' rel='bookmark' title='Permanent Link: Creating a Database Connection'>Creating a Database Connection</a></li>
<li><a href='http://www.codeitwell.com/aspnet-database-connection.html' rel='bookmark' title='Permanent Link: ASP.Net Database Connection'>ASP.Net Database Connection</a></li>
<li><a href='http://www.codeitwell.com/adding-items-to-listview-control.html' rel='bookmark' title='Permanent Link: Adding Items to ListView Control'>Adding Items to ListView Control</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/simple-data-entry-in-microsoft-access-database.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a Database Connection</title>
		<link>http://www.codeitwell.com/creating-a-database-connection.html</link>
		<comments>http://www.codeitwell.com/creating-a-database-connection.html#comments</comments>
		<pubDate>Thu, 01 May 2008 12:30:10 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[OLEDB]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=14</guid>
		<description><![CDATA[The database connection is so easy to do in .Net Framework. We will use Microsoft Access database for our example, the code will be written in C#.Net. For start create one Microsoft Access database (db.mdb), and create a table (Info) with the folowing columns ID (AutoNumber) FirstName (Text) LastName (Text) Then in button event (it's [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/simple-data-entry-in-microsoft-access-database.html' rel='bookmark' title='Permanent Link: Simple Data Entry In Microsoft Access Database'>Simple Data Entry In Microsoft Access Database</a></li>
<li><a href='http://www.codeitwell.com/aspnet-database-connection.html' rel='bookmark' title='Permanent Link: ASP.Net Database Connection'>ASP.Net Database Connection</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>The database connection is so easy to do in .Net Framework.<br />
We will use Microsoft Access database for our example, the code will be written in C#.Net.</p>
<p>For start create one Microsoft Access database (db.mdb), and create a table (Info) with the folowing columns</p>
<ul>
<li> ID (AutoNumber)</li>
<li> FirstName (Text)</li>
<li> LastName (Text)</li>
</ul>
<p>Then in button event (it's described <a title="Sample windows application" href="http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html">here</a>), add this code</p>
<pre class="csharp"><span style="color: #FF0000;">string</span> connStr = <span style="color: #808080;">&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;&quot;</span>;
OleDbConnection conn = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OleDbConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
conn.<span style="color: #0000FF;">ConnectionString</span> = connStr;
<span style="color: #FF0000;">string</span> cmdStr = <span style="color: #808080;">&quot;INSERT INTO Info (FirstName, LastName)&quot;</span> +
<span style="color: #808080;">&quot; VALUES('John', 'Smith');&quot;</span>;
OleDbCommand cmd = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OleDbCommand<span style="color: #000000;">&#40;</span>cmdStr, conn<span style="color: #000000;">&#41;</span>;
conn.<span style="color: #0000FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
cmd.<span style="color: #0000FF;">ExecuteNonQuery</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
conn.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>More connection strings for connecting to diferent databases from diferent interfaces you can find <a title="Connection Strings" href="http://www.connectionstrings.com/" target="_blank">here</a>. The connection string that we have used is to connect co Microsoft Access database from OleDb Connection.</p>
<p>When the event will be invoked, the program will try to connect to the database and insert the values 'John' in the column FirstName and 'Smith' in the column LastName. The ID will be increased by one automatically. And then the connection will be closed. The event can be invoked multiple times, then the records will duplicate.</p>
<p>The table will look like this, if the event is invoked 8 times</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/14.1.gif" alt="Database sample" /></p>
<p>Next time we will explain how to update the table dynamically.</p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/simple-data-entry-in-microsoft-access-database.html' rel='bookmark' title='Permanent Link: Simple Data Entry In Microsoft Access Database'>Simple Data Entry In Microsoft Access Database</a></li>
<li><a href='http://www.codeitwell.com/aspnet-database-connection.html' rel='bookmark' title='Permanent Link: ASP.Net Database Connection'>ASP.Net Database Connection</a></li>
<li><a href='http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html' rel='bookmark' title='Permanent Link: Creating a Windows Forms Application in C#'>Creating a Windows Forms Application in C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/creating-a-database-connection.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Write To File in C#</title>
		<link>http://www.codeitwell.com/write-to-file-in-cs.html</link>
		<comments>http://www.codeitwell.com/write-to-file-in-cs.html#comments</comments>
		<pubDate>Tue, 29 Apr 2008 11:05:03 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Streamwriter]]></category>
		<category><![CDATA[Write To File]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=12</guid>
		<description><![CDATA[Today we will create a console application written in C# for writing to files. We will use the StreamWriter class that is implemented in .Net Framework. Create new C# project (Ctrl+Shift+N), and choose Console Application from the Templates menu on the right. The editor will create the main code using System; using System.Collections.Generic; using System.Linq; [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/write-to-file-in-cpp.html' rel='bookmark' title='Permanent Link: Write To File In C++'>Write To File In C++</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-using-streamreader-class.html' rel='bookmark' title='Permanent Link: Read From File Using StreamReader Class'>Read From File Using StreamReader Class</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-in-cpp.html' rel='bookmark' title='Permanent Link: Read From File In C++'>Read From File In C++</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>Today we will create a console application written in C# for writing to files.<br />
We will use the StreamWriter class that is implemented in .Net Framework.</p>
<p>Create new C# project (Ctrl+Shift+N), and choose Console Application from the Templates menu on the right.<br />
The editor will create the main code</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Collections</span>.<span style="color: #0000FF;">Generic</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Linq</span>;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Text</span>;
&nbsp;
<span style="color: #0600FF;">namespace</span> WriteToFile
<span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">class</span> Program
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>Below the using System.Text; add this code</p>
<pre class="csharp"><span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">IO</span>;</pre>
<p>That is the namespace where the StreamWriter class is declared in.</p>
<p>Now, in the Main function add the folowing code</p>
<pre class="csharp">StreamWriter sw = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamWriter<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;text.txt&quot;</span><span style="color: #000000;">&#41;</span>;
sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>DateTime.<span style="color: #0000FF;">Now</span> + <span style="color: #808080;">&quot; : The program is executed&quot;</span><span style="color: #000000;">&#41;</span>;
sw.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Code&quot;</span><span style="color: #000000;">&#41;</span>;
sw.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;It&quot;</span><span style="color: #000000;">&#41;</span>;
sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Well.com&quot;</span><span style="color: #000000;">&#41;</span>;
sw.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>As you see, in the above code we are creating an object from the StreamWriter class, and we tell the object to write in the file "text.txt" (if the file doesn't exist, it will be created). So we are writing some text in the file using the WriteLine() and Write() functions. It's used and the DateTime class, so in the text file will be written the time where the file was changed.<br />
Very important is, when we finish with writing, we must close the file with sw.Close(). If the file isn't closed, we are leaving an opened handle, so other programms can't access that file.</p>
<p>This will be written to file</p>
<pre>29.04.2008 13:00:22 : The program is executed
www.codeitwell.com</pre>
<p>Every time we execute the program, the file will be erased, and then written again.<br />
If you don't want this, make this changes in the creating the StreamWriter object sw</p>
<pre class="csharp">StreamWriter sw = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamWriter<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;text.txt&quot;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>;</pre>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/write-to-file-in-cpp.html' rel='bookmark' title='Permanent Link: Write To File In C++'>Write To File In C++</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-using-streamreader-class.html' rel='bookmark' title='Permanent Link: Read From File Using StreamReader Class'>Read From File Using StreamReader Class</a></li>
<li><a href='http://www.codeitwell.com/read-from-file-in-cpp.html' rel='bookmark' title='Permanent Link: Read From File In C++'>Read From File In C++</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/write-to-file-in-cs.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a Windows Forms Application in C#</title>
		<link>http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html</link>
		<comments>http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html#comments</comments>
		<pubDate>Sun, 27 Apr 2008 19:34:02 +0000</pubDate>
		<dc:creator>Shabbir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codeitwell.com/?p=9</guid>
		<description><![CDATA[Just for start we will create very simple program, just for describing the basis of Windows Forms programming in C#. We are using the newest version of Visual Studio, Visual Studio 2008 for programming environtment. In it is implemented the .Net Framework 3.5, but we can make projects under .Net 2.0, 3.0 and 3.5. So, [...]


More Related Posts:<ol><li><a href='http://www.codeitwell.com/creating-a-database-connection.html' rel='bookmark' title='Permanent Link: Creating a Database Connection'>Creating a Database Connection</a></li>
<li><a href='http://www.codeitwell.com/remove-unused-using-statements.html' rel='bookmark' title='Permanent Link: Remove Unused Using Statements'>Remove Unused Using Statements</a></li>
<li><a href='http://www.codeitwell.com/aspnet-web-site-sample.html' rel='bookmark' title='Permanent Link: ASP.Net Web Site Sample'>ASP.Net Web Site Sample</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>Just for start we will create very simple program, just for describing the basis of Windows Forms programming in C#.</p>
<p>We are using the newest version of Visual Studio, Visual Studio 2008 for programming environtment. In it is implemented the .Net Framework 3.5, but we can make projects under .Net 2.0, 3.0 and 3.5.</p>
<p>So, let start.</p>
<p>Start your Visual Studio, and in the menus go to File -&gt; New -&gt; Project (Ctrl+Shift+N). Then in the dialog box under the Project Types tree view select C# -&gt; Windows, and on the right choose Windows Forms Application. Then fill the needed informations Name and Location. Then click OK.</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/1.1.gif" alt="Windows forms application create" /></p>
<p>After clicking OK, the project will be created. You will get a windows form with dimensions 300x300 pixels.</p>
<p>Move the cursor above the toolbox, drag one Button control and drop it on the form. You can change it's name by selecting Properties from it's context menu and change the property Text. In the properties you can find many customizations.</p>
<p>Double click on the button, the editor will create a Click event from the Button, and you will see code from the main form and the code from the button1 click event.</p>
<pre class="csharp"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> button1_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre>
<p>Then add this code between the brackets</p>
<pre class="csharp">MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hi there.<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span>+
<span style="color: #808080;">&quot;This is a Windows Forms Application Sample!&quot;</span>,
<span style="color: #808080;">&quot;Sample Message&quot;</span><span style="color: #000000;">&#41;</span>;</pre>
<p>Now debug the application. You can do that by pressing F5.</p>
<p>The application will start running, click the button and the message box will pop up.</p>
<p style="text-align: center;"><img src="http://www.codeitwell.com/wp-content/images/1.2.gif" alt="windows forms application sample" /></p>
<p>Close the message box, close the application.</p>
<p>This was really easy right? <img src='http://www.codeitwell.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you don't understand something, please comment here...</p>


<br /><p>More Related Posts:<ol><li><a href='http://www.codeitwell.com/creating-a-database-connection.html' rel='bookmark' title='Permanent Link: Creating a Database Connection'>Creating a Database Connection</a></li>
<li><a href='http://www.codeitwell.com/remove-unused-using-statements.html' rel='bookmark' title='Permanent Link: Remove Unused Using Statements'>Remove Unused Using Statements</a></li>
<li><a href='http://www.codeitwell.com/aspnet-web-site-sample.html' rel='bookmark' title='Permanent Link: ASP.Net Web Site Sample'>ASP.Net Web Site Sample</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeitwell.com/creating-a-windows-forms-application-in-cs.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

