<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-30721886</id><updated>2011-11-27T15:39:14.228-08:00</updated><title type='text'>C#.Net Articles</title><subtitle type='html'>by Thiagarajan.A</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-30721886.post-3540362470366408753</id><published>2009-11-03T07:47:00.000-08:00</published><updated>2009-11-03T08:31:22.795-08:00</updated><title type='text'>Remote Desktop using C#.Net</title><content type='html'>&lt;div&gt;&lt;strong&gt;Overview:&lt;/strong&gt;&lt;br /&gt;Remote Desktop Services is one of Microsoft Windows components to access a remote computer through network. Only the user interface of the application is presented at the client. Any input is redirected over to the remote computer over the network. At work we use Remote Desktop a great deal. It allows us to login to a remote server to perform health checks, deploy applications, troubleshoot problems, etc. We also use remote desktop often when we do WFH (work from home :)).&lt;br /&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 320px; DISPLAY: block; HEIGHT: 229px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5399907119631265106" border="0" alt="" src="http://2.bp.blogspot.com/_FryCrPC6daU/SvBS6lW5bVI/AAAAAAAAFTQ/utkW0oZofV8/s320/1.jpg" /&gt;&lt;br /&gt;Why do we want to write a .Net application to do this when you have the MS Terminal Services client available from OS? Well, consider if you want to work on 3 different application servers at the same time and want to toggle between these 3 servers quite often. With the MSTSC, we will be running 3 different clients for the 3 servers and it is difficult to manage the working environment. In .Net you can develop an application with tab control to load remote desktop sessions in different tabs in one window.However, tab control is not in scope of this article. That gives me an idea for my next article :)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Microsoft Terminal Services Control&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;We will be using AxMSTSCLib an ActiveX component in our program to connect to the remote computer. It's not that hard to build a remote desktop application in .Net.&lt;br /&gt;Microsoft has a "Microsoft RDP client control" ActiveX control that we will be using in our application.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;This is how we do it&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;We will start by creating a windows application in the Visual Studio IDE.&lt;br /&gt;Add reference to "Microsoft Terminal Services Control Type Library" from the COM tab. This will add MSTSCLib.dll to the project. &lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 320px; DISPLAY: block; HEIGHT: 262px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5399911881098170290" border="0" alt="" src="http://1.bp.blogspot.com/_FryCrPC6daU/SvBXPvNEj7I/AAAAAAAAFTY/x20dfB5qpqc/s320/2.jpg" /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;To add MSTSC to the toolbox, right click the toolbox and select "Choose Itemsâ€¦". Now add "Microsoft Terminal Services control from the COM tab.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 320px; DISPLAY: block; HEIGHT: 260px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5399912149596016754" border="0" alt="" src="http://4.bp.blogspot.com/_FryCrPC6daU/SvBXfXb8kHI/AAAAAAAAFTg/iMHRRiioo7M/s320/3.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;Drag the newly added control from toolbox to the form.&lt;br /&gt;Add 3 textbox and 2 button controls to the form. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 320px; DISPLAY: block; HEIGHT: 278px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5399912217717862354" border="0" alt="" src="http://1.bp.blogspot.com/_FryCrPC6daU/SvBXjVNdb9I/AAAAAAAAFTo/ppI2rjIhSmY/s320/4.jpg" /&gt;&lt;br /&gt;&lt;strong&gt;Connect Button - Click Event:&lt;/strong&gt;&lt;br /&gt;Here is how we write the Connect button click event.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;rdp.Server = txtServer.Text;&lt;br /&gt;rdp.UserName = txtUserName.Text;&lt;br /&gt;&lt;br /&gt;IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();&lt;br /&gt;secured.ClearTextPassword = txtPassword.Text;&lt;br /&gt;rdp.Connect();&lt;/blockquote&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;Now assign the properties (Server, UserName) of RDP control with the textbox values.&lt;br /&gt;Here's how easy to login to remote machine. However there is one catch, there is no direct method in RDP control through which you can pass the username and password to login to the remote desktop.&lt;br /&gt;Due to security reasons you have to implement an interface (IMsTscNonScriptable) to cast it separately.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote&gt;IMsTscNonScriptable secured = IMsTscNonScriptable)rdp.GetOcx();&lt;br /&gt;secured.ClearTextPassword = txtPassword.Text;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;strong&gt;Disconnect Button - Click Event:&lt;/strong&gt; &lt;/div&gt;&lt;div&gt;&lt;br /&gt;To disconnect from the remote desktop session, we just need to call the Disconnect() method.&lt;br /&gt;Before disconnecting, we want to ensure that the connection is still available. We don't want to disconnect if it is already disconnected (very clever huhJ)&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote&gt;if (rdp.Connected.ToString() == "1")&lt;br /&gt;rdp.Disconnect();&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Check the full source code &lt;a href="http://www.c-sharpcorner.com/UploadFile/thiagu304/remotedesktop10262009033113AM/remotedesktop.aspx?ArticleID=b55aa9a7-69ba-4ec3-90bf-6301d6ba0505"&gt;here&lt;/a&gt;. Please leave your valuable comments and questions.&lt;br /&gt;That's all folks! Happy Coding!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-3540362470366408753?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/3540362470366408753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=3540362470366408753' title='54 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/3540362470366408753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/3540362470366408753'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2009/11/remote-desktop-using-cnet.html' title='Remote Desktop using C#.Net'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_FryCrPC6daU/SvBS6lW5bVI/AAAAAAAAFTQ/utkW0oZofV8/s72-c/1.jpg' height='72' width='72'/><thr:total>54</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-116921670182964773</id><published>2007-01-19T06:24:00.000-08:00</published><updated>2007-01-19T06:25:02.230-08:00</updated><title type='text'>Snap It! - How to take screen shot using .Net</title><content type='html'>&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-size:130%;"&gt;&lt;big&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:100%;"&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;/big&gt;&lt;br /&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;We all would have used  snap shots (screen shots) to illustrate bugs or behavior or something that  others could understand by seeing them. For taking snap shots we just hit the  "Print Screen" key and copy it to Ms Paint and save it. Ever wondered how to  programmatically take a snap shot? Then this article is for  you.&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/610347/snapit1.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/400/570261/snapit1.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div style="text-align: center;"&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;Image-1 This is how the  application  looks&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;/div&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;big&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:100%;"&gt;Scenario&lt;/span&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Why do we need to take  snapshots programmatically? Consider a scenario where you want to report some  kind of behavior errors in an application. Human supervision is not possible  when the occurrence of error is random. So we just code a program to take snap  shots are regular intervals and store it as a image file. So that later you can  use it.&lt;br /&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-weight: bold;"&gt;GDI classes we need to  know&lt;/span&gt;&lt;/span&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;br /&gt;&lt;br /&gt;Lets see what we need to know before we do coding. We  need to have a little knowledge about GDI and graphics classes. The &lt;span style="font-weight: bold;"&gt;Graphics class&lt;/span&gt; provides methods for drawing  objects to the display device. A Graphics object is associated with a specific  device context. This class is used as a canvas to draw images. In order to  display anything in a window, you have to obtain a reference to the window's  Graphics object.&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;br /&gt;Next comes the Bitmap class. A Bitmap object is an  object used to work with images defined by pixel data. A bitmap consists of the  pixel data for a graphics image and its attributes.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt; &lt;span style="font-weight: bold;"&gt;Getting  Started&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;br /&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;To use the GDI classes we need to include &lt;span style="font-weight: bold;"&gt;System.Drawing.Imaging&lt;/span&gt; namespace in the "using"  section of the code. Go to the source view and add a string variable and a  property to the class. This string variable is used in the property to store and  retrieve the output file name.&lt;br /&gt;&lt;br /&gt;&lt;small&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;         &lt;span style="color: rgb(0, 153, 0);"&gt;// variable to store output file  name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;         &lt;span style="color: rgb(51, 51, 255);"&gt;private string&lt;/span&gt; strFilename;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;         &lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;         &lt;span style="color: rgb(0, 153, 0);"&gt;// Property for storing and retrieving output  file name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public string&lt;/span&gt; filename&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;&lt;br /&gt;       {&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;&lt;span style="color: rgb(51, 51, 255);"&gt; get&lt;/span&gt;{&lt;span style="color: rgb(51, 51, 255);"&gt;return&lt;/span&gt; strFilename;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;             &lt;span style="color: rgb(51, 51, 255);"&gt;set&lt;/span&gt;{strFilename=&lt;span style="color: rgb(51, 51, 255);"&gt;value&lt;/span&gt;;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;}&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;In the design view, add a button and a  savefiledialog to the form. Double click the button and go to the click event in  the code view.  Use the savefiledialog control to retrieve the output file name  from the user. And store the file name in the variable strFilename using the  property filename.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;                &lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-size:85%;"&gt;// Check user clicked OK  button&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Courier New,Courier,monospace;" &gt;&lt;br /&gt;           // Get the filename and put in the textbox and property&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;            &lt;span style="color: rgb(51, 51, 255);"&gt;if&lt;/span&gt;(saveFileDialog1.&lt;span style="color: rgb(51, 51, 255);"&gt;ShowDialog()&lt;/span&gt;!=DialogResult.Cancel)&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;br /&gt;          {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;filename=saveFileDialog1.FileName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;             }&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;Before  taking the snap shot we hide our application because we don't want our  application in the snap shot image. Sometimes even after hiding the application,  the snap shot pictures our application, this is because the application takes  few extra milliseconds to hide, so we &lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;make our  application to wait for some milliseconds.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new,courier,mono;"&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;             &lt;span style="font-size:85%;"&gt;this.&lt;span style="color: rgb(51, 51, 255);"&gt;Hide&lt;/span&gt;();&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;              &lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;             &lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;// Slow the thread to hide the  application before taking the snap&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;span style="font-size:85%;"&gt;          Thread.&lt;span style="color: rgb(51, 51, 255);"&gt;Sleep&lt;/span&gt;(200);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;span style="font-weight: bold;"&gt;How to Snap  It?&lt;/span&gt;&lt;/span&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;br /&gt;&lt;br /&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;Now  we create a Bitmap object to set the size of the screen. We use the width and  height of the application screen to capture the snap shot. So the user can place  our application screen on any area of the screen, move/resize to get the snap  shot. To make the user more comfortable in selecting the snap shot area we make  the application screen semi-transparent by setting the opacity of the form to  50%&lt;br /&gt;&lt;br /&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/424390/snapit2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/400/568918/snapit2.jpg" alt="" border="0" /&gt;&lt;/a&gt;  &lt;div style="text-align: center;"&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;img style="width: 658px; height: 386px;" alt="Resizing the application" src="file:///C:/Documents%20and%20Settings/talagars/My%20Documents/Articles/snapit2.JPG" /&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;Image-2 Resizing and  Moving the  screen&lt;br /&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;/div&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;br /&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Courier New,Courier,monospace;" &gt;             // Setting the size of the screen for the bitmap&lt;/span&gt; &lt;/span&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;span style="font-size:85%;"&gt;             Bitmap bmp= &lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt;  Bitmap(this.Width,this.Height,PixelFormat.Format32bppArgb);&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;A  Graphics object is required to get the image bounds and create the actual  picture. So we initialize a Graphics object and get the image bounds from the  Bitmap that we have already created. CopyFromScreen method is used to get the  snap shot from the screen. Based on the user selection of the file type in the  savefiledialog box,  we use different image formats to save the file using  Bitmap.Save function.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;small style="font-weight: bold; color: rgb(0, 153, 0);"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;           &lt;span style="font-size:85%;"&gt; //  Saving file in the selected image format&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;&lt;small&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;             &lt;span style="font-size:85%;"&gt;bmp.&lt;span style="color: rgb(51, 51, 255);"&gt;Save&lt;/span&gt;(filename,ImageFormat.Jpeg);&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-size:85%;"&gt;After  saving the picture we show the application back by using the following  statement&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;small&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;             &lt;span style="color: rgb(0, 153, 0);"&gt;// Showing the application  again&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;&lt;span style="font-size:85%;"&gt;            this.&lt;span style="color: rgb(51, 51, 255);"&gt;Show&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;span style="font-weight: bold;font-size:85%;" &gt;Viewing the snap shot&lt;/span&gt;&lt;/big&gt;&lt;br /&gt;&lt;br /&gt;Now the  screen is captured and the picture is saved. We need to view the snap shot.  There is an option available to see how your snap shot has come up, just right  after saving the file. We use Process class of System.Diagnostic namespace to  view the image file.&lt;br /&gt;&lt;br /&gt;&lt;small style="font-weight: bold;"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;              // Viewing the image&lt;/span&gt;&lt;br /&gt;           Process pr= &lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt;  Process();&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;               pr.StartInfo.FileName=filename;&lt;/span&gt; &lt;/span&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;span style="font-size:85%;"&gt;               pr.Start();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/small&gt; &lt;div style="text-align: center;"&gt;&lt;span style="font-size:85%;"&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;img style="width: 658px; height: 386px;" alt="Viewing the image" src="file:///C:/Documents%20and%20Settings/talagars/My%20Documents/Articles/snapit3.JPG" /&gt;&lt;/span&gt;&lt;/small&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/148371/snapit3.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/400/140454/snapit3.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;img style="width: 658px; height: 386px;" alt="Viewing the image" src="file:///C:/Documents%20and%20Settings/talagars/My%20Documents/Articles/snapit3.JPG" /&gt;&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;/span&gt;&lt;/small&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="text-align: center;"&gt;Image -3 Viewing the saved image  file&lt;br /&gt;&lt;/div&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/small&gt;When the  Start method is executed the image file is opened in the respective application  configured in the system.&lt;br /&gt;Thats all folks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-116921670182964773?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/116921670182964773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=116921670182964773' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116921670182964773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116921670182964773'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2007/01/snap-it-how-to-take-screen-shot-using.html' title='Snap It! - How to take screen shot using .Net'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-116892731500003994</id><published>2007-01-15T21:50:00.000-08:00</published><updated>2007-01-15T23:28:17.743-08:00</updated><title type='text'>File Splitter in .Net</title><content type='html'>&lt;big&gt;&lt;big&gt;&lt;span style="font-weight: bold;font-family:Times New Roman;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;span style="font-weight: bold;font-family:Times New Roman;" &gt;&lt;small&gt;Introduction&lt;br /&gt;&lt;/small&gt;&lt;/span&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Times New Roman;"&gt;I love to do utility programs in .Net. And  this is one of them. As I was playing with JSplit (a free file splitter  program), I wondered if I could do it in .Net. The framework supports file  operations like reading files in bytes and creating them. It is indeed easy to  do file operations in .Net&lt;/span&gt; &lt;big&gt; &lt;span style="font-weight: bold;font-family:Times New Roman;" &gt;Basics on File  operations&lt;br /&gt;&lt;/span&gt;&lt;small&gt; &lt;span style="font-family:Times New Roman;"&gt;The namespace &lt;/span&gt;&lt;span style="font-weight: bold;font-family:Times New Roman;" &gt;System.IO&lt;/span&gt;&lt;span style="font-family:Times New Roman;"&gt; provides classes for file operations.  &lt;/span&gt;&lt;span style="font-weight: bold;font-family:Times New Roman;" &gt;StreamReader&lt;/span&gt;&lt;span style="font-family:Times New Roman;"&gt; is a class which provides methods to read  a file in different modes. It allows the user to read file by number of  characters, by line, by block and to the end of the file. There is another class  &lt;/span&gt;&lt;span style="font-weight: bold;font-family:Times New Roman;" &gt;FileStream&lt;/span&gt;&lt;span style="font-family:Times New Roman;"&gt; which allows the user to read file by  number of bytes. This is what we are going to use.&lt;/span&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;br /&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/426378/FileSplitter.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/400/523201/FileSplitter.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/909754/FileSplitter2.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/400/693033/FileSplitter2.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;br /&gt;&lt;br /&gt;&lt;big&gt;&lt;span style="font-weight: bold;font-family:Times New Roman;" &gt;Getting  Started&lt;br /&gt;&lt;/span&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;span style="font-family:Times New Roman;"&gt;Lets  begin by creating a windows application with a textbox, a numericupdown control,  a label and three buttons.&lt;/span&gt; &lt;span style="font-family:Times New Roman;"&gt;Add a openfileDialog control and add some  code to extract the filename from the dialog and to put it in the textbox when  the browse button is clicked.&lt;/span&gt;&lt;br /&gt;&lt;small&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;             &lt;span style="color: rgb(51, 51, 255);"&gt;if&lt;/span&gt;(openFileDialog1.ShowDialog()==DialogResult.OK)&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;             {&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;span style="font-weight: bold;"&gt;                 txtFileName.Text=openFileDialog1.FileName;&lt;/span&gt;&lt;br /&gt;&lt;big&gt; &lt;span style="font-family:Times New Roman;"&gt;Now change the Maximum value of the  numericupdown control to 1. Change the backcolor of the label to black and  forecolor to green (to give a matrix screen effect)&lt;br /&gt;&lt;br /&gt;Set the text property  of the buttons to "Calculate" and "Split".&lt;br /&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;Include the namespaces  System.IO and System.Text in the Using section.&lt;br /&gt;&lt;br /&gt;&lt;big&gt;&lt;span style="font-weight: bold;"&gt;Calculate Method&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;small&gt;In Calculate  method we are going to calculate the number of parts the file will be splitted  based on the file size and the split size specified by the user.&lt;br /&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;Double  click on the calculate button to go to the Click event. Now initialize the class  FileStream by passing the filename from the textbox and specifying file mode and  file access parameters.&lt;br /&gt;&lt;br /&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;        &lt;span style="font-weight: bold;"&gt;FileStream FR=&lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt;  FileStream(txtFileName.Text,FileMode.Open,  FileAccess.Read);&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;&lt;br /&gt;The number of parts is caculated  by dividing the file size (in bytes) and user selected split size. This is made  to display in the label.&lt;br /&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;        &lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt;  no_of_parts = Int32.Parse(FR.Length.ToString())/intByteSize;&lt;br /&gt;    &lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt;  intmod=Int32.Parse(FR.Length.ToString())%intByteSize;&lt;br /&gt;       &lt;br /&gt;     &lt;span style="color: rgb(51, 204, 0);"&gt;//Include the remaining  bytes&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(51, 51, 255);"&gt;if&lt;/span&gt;(intmod  &gt; 0)&lt;br /&gt;        no_of_parts=no_of_parts+1;&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;&lt;br /&gt;&lt;big&gt;&lt;span style="font-weight: bold;"&gt;Split Method&lt;/span&gt;&lt;/big&gt;&lt;br /&gt;&lt;br /&gt;In this method we are  going to split the file in to user desired size and number of parts. We again  use the FileStream class to read the file. But here we are going to read the  file by number of bytes required for each part. So after reading a block of  bytes required for a part we write it to a file by using FileStream but in the  create file mode and write file access.&lt;br /&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;          &lt;span style="color: rgb(51, 204, 0);"&gt;//Read the file by number of bytes and  create part files&lt;/span&gt;&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;          &lt;span style="color: rgb(51, 51, 255);"&gt;for&lt;/span&gt;(&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt; i=0;i&lt;no_of_parts;i++)&gt;&lt;/no_of_parts;i++)&gt;&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;          {&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;            &lt;span style="color: rgb(51, 51, 255);"&gt;if&lt;/span&gt;(intmod&gt;0 &amp;&amp;amp;  i==no_of_parts-1)&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;            {&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;              by=&lt;span style="color: rgb(51, 51, 255);"&gt;new byte&lt;/span&gt;[intmod];&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;              FR.Read(by,0,intmod);&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;            }&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;            &lt;span style="color: rgb(51, 51, 255);"&gt;else&lt;/span&gt;&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;            {&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;              by=&lt;span style="color: rgb(51, 51, 255);"&gt;new  byte&lt;/span&gt;[intByteSize];&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;              FR.Read(by,0,intByteSize);&lt;/span&gt; &lt;span style="font-weight: bold;font-family:Courier New,Courier,monospace;" &gt;            }&lt;/span&gt;&lt;/small&gt;&lt;br /&gt;&lt;br /&gt;FileStream's WriteByte function is used to write the  bytes to a file. Like this number of files are generated for the number of parts  calculated. Each file is written with a dynamic name by appending some  incrementing number to the file name.&lt;br /&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;&lt;small  style="font-weight: bold;font-family:Courier New,Courier,monospace;"&gt;            &lt;span style="color: rgb(51, 51, 255);"&gt;foreach&lt;/span&gt;(&lt;span style="color: rgb(51, 51, 255);"&gt;byte&lt;/span&gt; b &lt;span style="color: rgb(51, 51, 255);"&gt;in&lt;/span&gt; by)&lt;br /&gt;       {&lt;br /&gt;          FW.WriteByte(b);&lt;br /&gt;       }&lt;/small&gt;&lt;br /&gt;&lt;br /&gt;&lt;big&gt;&lt;span style="font-weight: bold;"&gt;Batch File&lt;br /&gt;&lt;/span&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;br /&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;The significance of a  file splitter is the ability to reunite the file without the actual splitter  application. For this, we create a batch file in the split function to reunite  the files and create the actual file. This batch file contains statements to  combine the part files and generate the actual file.&lt;br /&gt;&lt;br /&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;            StringBuilder SB=  &lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; StringBuilder();&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;            SB.Append("Copy  /b " + tempfilenames + " \"" + filename + "\"");&lt;/span&gt; &lt;span style="font-family:Courier New,Courier,monospace;"&gt;             SW.Write(SB.ToString());&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;br /&gt;&lt;br /&gt;We use StringBuilder class to  generate the statement for the batch file. The statement includes the command  for uniting the files followed by the filenames. This command should be  dynamically added to include the filenames. Now we write this statement to a  file and save. The content of the batch file should look like the following  statement.&lt;br /&gt;&lt;br /&gt;&lt;small style="font-weight: bold;"&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;Copy /b "test.pdf0"  +"test.pdf1" +"test.pdf2"  "test.pdf"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/50146/FileSplitter3.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/400/228842/FileSplitter3.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;big&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;span style="font-family:Times New Roman;"&gt;Conclusion&lt;/span&gt;&lt;/span&gt;&lt;/big&gt;  &lt;big&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;small&gt;&lt;span style="font-family:Courier New,Courier,monospace;"&gt;&lt;big&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;big&gt;&lt;small&gt;&lt;big&gt;&lt;small&gt;&lt;span style="font-family:Times New Roman;"&gt;While using file operations we should  ensure that the file is closed after the read/write process. Thats all  folks!&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/thiagu304/FileSplitter01142007232713PM/FileSplitter.aspx?ArticleID=c4dd6dbf-09c9-4a42-861f-6ed94683360e"&gt;For further reading and code download&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/span&gt;&lt;/big&gt;&lt;/span&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/big&gt;&lt;/small&gt;&lt;/small&gt;&lt;/big&gt;&lt;/big&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-116892731500003994?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/116892731500003994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=116892731500003994' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116892731500003994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116892731500003994'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2007/01/file-splitter-in-net.html' title='File Splitter in .Net'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-116671038218824349</id><published>2006-12-21T06:11:00.000-08:00</published><updated>2007-01-15T23:33:06.780-08:00</updated><title type='text'>Find and Replace for multiline text</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;Many of us would have used "Find and Replace" option available in our IDE and in many of the text editors. This functionality finds a single line of text given and replaces with the given text in the current document as well as in the files under a given folder. But how would you find and replace a multiline text? In this article I have tried to explain that.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/493568/FindnReplace.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/320/261470/FindnReplace.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;The project included in this article has a simple file reading operation. For the beginners first let me explain how to read files. You can skip this section if you are familiar with file operations.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;File Operations&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The first step is to include the System.IO namespace in the using directive.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;System.IO namespace has &lt;span style="font-weight: bold;"&gt;DirectoryInfo&lt;/span&gt; class which is used for typical operations such as copying, moving, renaming, creating, deleting and enumerating through directories and sub-directories. Files under a specific directory can be found using this class.&lt;br /&gt;&lt;br /&gt;The following statement instantiates DirectoryInfo class with a folder path from the text box.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;DirectoryInfo DI= &lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; DirectoryInfo(txtFolder.Text);&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;To get the file information we use the following statement.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;foreach&lt;/span&gt;(FileInfo FI &lt;span style="color: rgb(51, 51, 255);"&gt;in&lt;/span&gt; DI.GetFiles())&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;The GetFiles method of the DirectoryInfo class, returns an array of FileInfo object. The &lt;span style="font-weight: bold;"&gt;FileInfo&lt;/span&gt; class like DirectoryInfo has operations for reading, copying, moving, renaming, creating and deleting files.&lt;br /&gt;&lt;br /&gt;Now we use a StreamReader object to read the file.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;StreamReader SR= &lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; StreamReader(FI.OpenRead());&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;We use the following statement to read a line and assign it to a string variable.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;s=SR.ReadLine();&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Search Operation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We read each line and store it in a temporary variable appending a new line character ("\r\n") at the end of the line.&lt;br /&gt;This will differentiate each line for searching multiline text.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;temp=temp+s+"\r\n";&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;Now to search the string we use IndexOf() method in the temporary variable with the search text as parameter.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;pos=temp.IndexOf(txtFind.Text);&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;The above statement returns the position of the search text.&lt;br /&gt;We use a list box to record the number of files that matches the search text and the occurence of the first position.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Replace Operation&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;For the replace functionality, we use Replace() method in the temporary variable with search string and string to replace as arguments.&lt;br /&gt;temp=temp.Replace(txtFind.Text,txtReplace.Text);&lt;br /&gt;&lt;br /&gt;To reflect this change in the actual file, we need to write it to the file. So we use StreamWriter object to write to the file.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="margin-left: 40px;font-family:verdana;"&gt;&lt;span style="font-size:100%;"&gt;StreamWriter SW= &lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; StreamWriter(FI.OpenWrite());&lt;br /&gt;SW.Write(temp);&lt;br /&gt;SW.Close();&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-size:100%;"&gt;The source code for the project can be downloaded &lt;a href="http://thiagarajan.alagarsamy.googlepages.com/FindnReplace.zip"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/thiagu304/FindnReplace12222006022310AM/FindnReplace.aspx?ArticleID=b6ed7667-5de6-42e1-a5fb-80dae92457a0"&gt;For further reading and source code download&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;Thats all folks!!!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-116671038218824349?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/116671038218824349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=116671038218824349' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116671038218824349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116671038218824349'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2006/12/find-and-replace-for-multiline-text.html' title='Find and Replace for multiline text'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-116369163961249298</id><published>2006-11-16T07:14:00.000-08:00</published><updated>2006-11-20T03:35:59.196-08:00</updated><title type='text'>Consuming a webservice from behind a proxy firewall</title><content type='html'>I was trying to access a webservice from my office which is behind a proxy firewall, I was annoyed by seeing the following error message&lt;br /&gt;&lt;br /&gt;"&lt;span style="COLOR: rgb(255,0,0)"&gt;- The request failed with HTTP status 407: Proxy Authentication Required&lt;/span&gt;"&lt;br /&gt;&lt;br /&gt;I knew that it is something to do with the firewall proxy. So I googled my doubt and the error text but couldn't get a descent solution. Then I tried with the options in the command WSDL that we use to generate a proxy class (not to be confused with firewall proxy) for our webservice.&lt;br /&gt;&lt;br /&gt;I found the following options.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;/proxy:&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;/proxyusername:&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;/proxypassword:&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;/proxydomain:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But I didn't know how to use these options (I should admit that I am not good at DOS). Then I googled these options and got some answers which I am going to share with you now.&lt;br /&gt;&lt;br /&gt;/proxy: is the url of the proxy server with the port number. For E.g., if your proxy server address is 255.255.255.255 and the port is 8001 then your proxy url is &lt;a href="http://255.255.255.255:8001"&gt;http://255.255.255.255:8001&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;/proxyusername: is the username of your proxy server and /proxypassword: is the password of your proxy server.&lt;br /&gt;&lt;br /&gt;/proxydomain: is the domain name of your server.&lt;br /&gt;&lt;br /&gt;So the WSDL command should be something like this.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;c:\WSDL /proxy:http://255.255.255.255:8001 &lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;/proxyusername:uname&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;/proxypassword:pwd /proxydomain:lotus &lt;a href="http://thiagu007.tk.105.webhostforasp.net/"&gt;http://thiagu007.tk.105.webhostforasp.net/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;service1.asmx?wsdl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above command will download the proxy class file for the webservice.&lt;br /&gt;&lt;br /&gt;But this is not the end of the show. We need to consume the service. The first thing we need to do is compile the class to a dll.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;c:\csc.exe \t:library service1.cs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Then create a windows application project in Visual Studio and add the dll as a reference. Now you can use the class that is available in the dll and create an instance of it. But calling the web method from the webservice will again display the same error.&lt;br /&gt;&lt;br /&gt;To resolve this you have to create a WebProxy. This is again the authenication information for firewall proxy.&lt;br /&gt;&lt;br /&gt;To instantiate the WebProxy class you need to include the namespace System.Net in the "using" part.&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(51,51,255)"&gt;using&lt;/span&gt; System.Net;&lt;br /&gt;&lt;br /&gt;Now you can instantiate WebProxy class as follows,&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;// Instantiate the WebProxy class&lt;/span&gt;&lt;br /&gt;WebProxy myProxy = &lt;span style="COLOR: rgb(51,51,255)"&gt;new&lt;/span&gt; WebProxy(&lt;a href="http://255.255.255.255:8001,true"&gt;http://255.255.255.255:8001,&lt;span style="COLOR: rgb(51,51,255)"&gt;true&lt;/span&gt;&lt;/a&gt;);&lt;br /&gt;myProxy.Credentials = &lt;span style="COLOR: rgb(51,51,255)"&gt;new&lt;/span&gt; NetworkCredential("uname", "pwd", "lotus");&lt;br /&gt;&lt;br /&gt;Now, the proxy should be assigned to the Service class and the function can be called.&lt;br /&gt;&lt;br /&gt;&lt;span style="COLOR: rgb(0,153,0)"&gt;// Instantiate the WebService class&lt;br /&gt;&lt;/span&gt;Service1 sr=&lt;span style="COLOR: rgb(51,51,255)"&gt;new&lt;/span&gt; Service1();&lt;br /&gt;sr.Proxy =myProxy; &lt;span style="COLOR: rgb(0,153,0)"&gt;// Set the proxy to the class&lt;/span&gt;&lt;br /&gt;String str=sr.HelloWorld(); &lt;span style="COLOR: rgb(0,153,0)"&gt;// Calling the web method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This will call the method that is available in the webservice by authenticating the proxy server's credentials.&lt;br /&gt;&lt;br /&gt;Happy Coding :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-116369163961249298?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/116369163961249298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=116369163961249298' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116369163961249298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116369163961249298'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2006/11/consuming-webservice-from-behind-proxy.html' title='Consuming a webservice from behind a proxy firewall'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-116281519936931484</id><published>2006-11-06T03:54:00.000-08:00</published><updated>2006-11-06T04:16:24.976-08:00</updated><title type='text'>Dynamic Code Compilation</title><content type='html'>Welcome to dynamic code compilation. This article throws light on how a code can be built dynamically, compiled and run. The scenario of dynamic code compilation may arise when you want an application to upgrade (or rewrite) another application.&lt;br /&gt;     Lets jump in to coding. The namespaces that we are going to use in this project are&lt;br /&gt;&lt;ul&gt;&lt;li&gt;    System.CodeDom&lt;/li&gt;&lt;li&gt;    System.CodeDom.Compiler&lt;/li&gt;&lt;li&gt;    Microsoft.CSharp&lt;/li&gt;&lt;/ul&gt;      The &lt;b&gt;System.CodeDom&lt;/b&gt; namespace contains classes that can be used to represent the elements and structure of a source code document. The classes in this namespace can be used to model the structure of a source code document that can be output as source code in a supported language using the functionality provided by the &lt;span class="linkTerms"&gt;System.CodeDom.Compiler&lt;/span&gt; namespace.&lt;br /&gt;&lt;br /&gt;   The &lt;b&gt;Microsoft.CSharp&lt;/b&gt; namespace contains classes that support compilation and code generation using the C# language.&lt;br /&gt;&lt;br /&gt;At first we need to instantiate the class CSharpCodeProvider. Then create a complier using CreateCompiler() function of CSharpCodeProvider class and assign to the interface ICodeCompiler.&lt;br /&gt;&lt;br /&gt;          &lt;span style="font-family:courier new;"&gt;CSharpCodeProvider codeProvider = &lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);font-family:courier new;" &gt;new&lt;/span&gt;&lt;span style="font-family:courier new;"&gt; CSharpCodeProvider();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;     ICodeCompiler icc = codeProvider.CreateCompiler();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Then set the parameters for the compiler using CompilerParameters class. Set parameters like GenerateExecutable, OutputAssembly&lt;br /&gt;&lt;br /&gt;        &lt;span style="font-family:courier new;"&gt;System.CodeDom.Compiler.CompilerParameters parameters = &lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; CompilerParameters();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    parameters.GenerateExecutable = &lt;span style="color: rgb(51, 51, 255);"&gt;true&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    parameters.OutputAssembly = "Out.exe";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now declare a String variable and write the source code for the new application/program.  Now instantiate CompilerResults class with compiler parameters and the source code as below.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      String sourcecode;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      sourcecode="using System;namespace SampleApp{class  Class1{[STAThread] static void Main(string[] args)        {            Console.WriteLine(\"I am born to live!\");Console.Read();        }    }}";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      CompilerResults results = icc.CompileAssemblyFromSource(parameters,sourcecode);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:georgia;"&gt;Now the code is compiled. If you want to run the compiled EXE, start the process by&lt;br /&gt;&lt;br /&gt;              Process.Start("Out.exe");&lt;br /&gt;&lt;br /&gt;Thats all folks!....&lt;br /&gt;Happy coding&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-116281519936931484?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/116281519936931484/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=116281519936931484' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116281519936931484'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/116281519936931484'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2006/11/dynamic-code-compilation.html' title='Dynamic Code Compilation'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-115276833782213154</id><published>2006-07-12T22:25:00.000-07:00</published><updated>2006-07-12T22:39:03.203-07:00</updated><title type='text'>Calling APIs, The .Net Way!</title><content type='html'>&lt;big&gt;&lt;span style="font-weight: bold;"&gt;What is Windows API?&lt;/span&gt;&lt;/big&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;span style="font-family:Verdana;"&gt;The Windows API is the name given by Microsoft to the core set of application programming interfaces available in the Microsoft Windows operating systems. It is designed for usage by C/C++ programs and is the most direct way to interact with a Windows system for software applications.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The functionality provided by the Windows API can be grouped into various categories like Base Services, Graphics Device Interface, User Interface, Common Dialog Box Library, Common Control Library, Windows Shell, Network Services.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;big style="font-weight: bold;"&gt;&lt;br /&gt;The .Net Way!&lt;/big&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Now we will see how to call an API function in .Net. As we all know that .Net supports Interop Services, its very easy to call an API function using the namespace "System.Runtime.InteropServices".&lt;br /&gt;&lt;br /&gt;Before going to the coding section, lets start with an example. Here I am going to use Windows API for hiding the mouse cursor and showing it back. For this purpose, I am going to use the API user32.ShowCursor function which is under the category User Interface.&lt;br /&gt;&lt;br /&gt;Let us start the coding by first including the namespace "System.Runtime.InteropServices". This namespace provides a wide variety of members that support COM interop and platform invoke services. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;    using &lt;/span&gt;System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;span style="font-family:Verdana;"&gt;Then comes the declaration part. Here we declare the API function that we are going to use. Here we have to specify the dll to which the function refers. In our case it is User32.dll.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     [DllImport("user32.dll")]&lt;br /&gt;     &lt;span style="color: rgb(51, 51, 255);"&gt;static extern int&lt;/span&gt; ShowCursor(&lt;span style="color: rgb(51, 51, 255);"&gt;bool&lt;/span&gt; bShow);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The Statement DllImport is an attribute which you use to define platform invoke methods for accessing unmanaged APIs. This definition should be made inside the main class like other member functions and variables.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The interesting part is calling the API function. It is very straight forward. Just use the following statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; ShowCursor(&lt;span style="color: rgb(51, 51, 255);"&gt;false&lt;/span&gt;);   &lt;span style="color: rgb(153, 255, 153);"&gt; &lt;span style="color: rgb(93, 156, 93);"&gt;// Hide cursor&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; ShowCursor(&lt;span style="color: rgb(51, 51, 255);"&gt;true&lt;/span&gt;);    &lt;span style="color: rgb(93, 156, 93);"&gt;// Show cursor&lt;/span&gt;&lt;br /&gt;&lt;big&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Some Tips...&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;small&gt;    &lt;span style=""&gt;&lt;span style="font-family:Verdana;"&gt;For beginners, implementing APIs is a tough job. There is a quick reference website (&lt;/span&gt;&lt;a style="font-family: Verdana;" href="http://www.pinvoke.net/"&gt;www.pinvoke.net&lt;/a&gt;&lt;span style="font-family:Verdana;"&gt;) which provides the structure and sample code (sometimes)&lt;/span&gt;&lt;/span&gt;&lt;/small&gt;&lt;span style=""&gt;&lt;span style="font-weight: bold;font-family:Verdana;" &gt; &lt;/span&gt;&lt;/span&gt;&lt;small&gt;&lt;span style=""&gt;&lt;span style="font-family:Verdana;"&gt;for all the APIs. But first you need to know which API function is needed for your use. You can find it easily by searching in Google. Happy Coding!&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/small&gt;&lt;small&gt;&lt;small&gt; &lt;/small&gt;&lt;br /&gt;&lt;br /&gt;&lt;/small&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/big&gt;&lt;small&gt;&lt;br /&gt;&lt;br /&gt;&lt;/small&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-115276833782213154?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/115276833782213154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=115276833782213154' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/115276833782213154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/115276833782213154'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2006/07/calling-apis-net-way.html' title='Calling APIs, The .Net Way!'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-115227760665201648</id><published>2006-07-07T05:12:00.000-07:00</published><updated>2007-01-02T21:02:05.150-08:00</updated><title type='text'>Excel Automation in .Net</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Verdana;"&gt;Excel Automation is a buzz word in both webapps and winapps. In the programming life (like Mr.Anderson neo) I guess almost every one could have come across this word. For others let me go further in detail. Excel Automation is automating some or all of the process involved in creating or updating excel worsheets.&lt;/span&gt;&lt;span style="font-family:arial;"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The real life scenario of an excel automation can be a daily account maintenance where you have an excel sheet template with graphs and calculations already in place except the data. So you want the data to be pulled in from a database and written to the excel sheet. After this the template takes care of the data by manipulating for graph generation.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;For the above said scenario we can go for a simple console application in .Net. Why I didn't go for an ASP.Net web application? Because running a web application requires a browser to be opened and closed. This becomes tedious when you schedule the process using windows scheduler to occur in particular intervals. And running a console based application is quite easy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/362159/XL-file.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/320/885216/XL-file.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Pardon me for beating around the bush. Now let us jump in to the good part (coding). For this automation process we need to follow the below steps&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;1. Add a referrence to the Microsoft Excel object library COM component.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;2. Add the namespace Excel&lt;/span&gt;&lt;span style="font-family:arial;"&gt;  &lt;/span&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;3. Instantiate the class Excel.ApplicationClass as below&lt;/span&gt;&lt;span style="font-family:arial;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style=";font-family:Courier New,Courier,monospace;font-size:85%;"  &gt;&lt;br /&gt;Excel.Application xl=&lt;span style="color: rgb(51, 51, 255);"&gt;new&lt;/span&gt; Excel.ApplicationClass();&lt;/span&gt;&lt;/span&gt; &lt;p  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;    4.   To open an excel file,&lt;/span&gt;&lt;/p&gt; &lt;p  style="font-family:Courier New,Courier,monospace;"&gt;&lt;span style="font-size:85%;"&gt;            Excel.Workbook wb=xl.Workbooks.Open(Environment.CurrentDirectory+"/SampleExcel.xls",0, &lt;span style="color: rgb(51, 51, 255);"&gt;false&lt;/span&gt;, 5, System.Reflection.Missing.Value, System.Reflection.Missing.Value, &lt;span style="color: rgb(51, 51, 255);"&gt;false&lt;/span&gt;, System.Reflection.Missing.Value, System.Reflection.Missing.Value,&lt;span style="color: rgb(51, 51, 255);"&gt;true&lt;/span&gt;, &lt;span style="color: rgb(51, 51, 255);"&gt;false&lt;/span&gt;, System.Reflection.Missing.Value, &lt;span style="color: rgb(51, 51, 255);"&gt;false&lt;/span&gt;, &lt;span style="color: rgb(51, 51, 255);"&gt;false&lt;/span&gt;, &lt;span style="color: rgb(51, 51, 255);"&gt;false&lt;/span&gt;); &lt;span style="color: rgb(51, 204, 0);"&gt;//Open the excel sheet&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;span style=";font-family:arial;font-size:100%;"  &gt;&lt;span style="font-family:georgia;"&gt;    5.    To read cell(s) in the worksheet,&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt; Excel.Sheets xlsheets=wb.Sheets; &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Get the sheets from workbook&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;               Excel.Worksheet excelWorksheet = (Excel.Worksheet)xlsheets[1];        &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Select the first sheet&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;          Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("B4:FZ4",Type.Missing);  &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Select a range of cells&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;              Excel.Range excelCell2 = (Excel.Range)excelWorksheet.get_Range("A5:A5",Type.Missing); &lt;/span&gt;         &lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Select a single cell&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt; Console.WriteLine(excelCell2.Cells.Value2.ToString()); &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Print the value of the cell for a single cell selection&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;              System.Array myvalues = (System.Array)excelCell.Cells.Value2;          &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Assign it to an array&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt; string[] strArray = ConvertToStringArray(myvalues); &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Convert array into String array&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;              foreach (string str in strArray)&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt; Console.WriteLine(" Text in Cell " + str); &lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;//Loop through the array to print the values in the cell&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 204, 0);font-family:courier new;font-size:85%;"  &gt;   &lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger/7529/2900/1600/901185/XL-Automation.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger/7529/2900/400/558822/XL-Automation.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;     6.  To save a value in a cell&lt;/span&gt;&lt;br /&gt;&lt;span style=";font-family:Courier New,Courier,monospace;font-size:85%;"  &gt;             excelCell2.Cells.Value2="SampleText";                &lt;span style="color: rgb(51, 204, 0);"&gt;//Assign a value to the cell&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;  &lt;/span&gt;&lt;span style=";font-family:Courier New,Courier,monospace;font-size:85%;"  &gt;            &lt;br /&gt;wb.Save();                                                                          &lt;span style="color: rgb(51, 204, 0);"&gt;//Save the workbook&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;     7.    Finally Quit the Excel Application&lt;/span&gt;&lt;br /&gt;&lt;span style=";font-family:Courier New,Courier,monospace;font-size:85%;"  &gt;               xl.Quit();&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-115227760665201648?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/115227760665201648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=115227760665201648' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/115227760665201648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/115227760665201648'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2006/07/excel-automation-in-net.html' title='Excel Automation in .Net'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-30721886.post-115217204803280719</id><published>2006-07-06T00:41:00.000-07:00</published><updated>2006-07-12T06:30:30.953-07:00</updated><title type='text'>Passing Data Between Forms - WinForms</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:verdana;"&gt;Some of you would have faced a scenario where you wanted to pass data from one form to another in WinForms. Honestly, I too had a similar problem (that’s why I am writing this article!).&lt;br /&gt;&lt;br /&gt;There are so many methods (How many? I don’t know) to pass data between forms in windows application. In this article let me take four important (easiest) ways of accomplishing this.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;ol style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Using constructor &lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Using objects &lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Using properties &lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Using delegates&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;The Constructor Approach&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;/span&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;strong&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;This could be the easiest method of all. A method is invoked whenever you instantiate an object. This method is called a constructor. Code a constructor for form2 class with one string parameter. In the constructor assign the text to the label’s text property. Instantiate form2 class in form1’s button click event handler using the constructor with one string parameter and pass the textbox’s text to the constructor.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;/span&gt;&lt;h2 class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;The Object Approach&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;o:p&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;&lt;span style=";font-family:Times New Roman;font-size:100%;"  &gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;span style="font-size:0;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Objects are reference types, and are created on the heap, using the keyword new. Here we are going to pass data using objects. The approach is simple; in form2 we are going to instantiate form1 class. Then instantiate form2 in the button click event handler of form1. After this we are going to pass form1 object to the form2 using form2’s form1 object. The last step is to invoke the form2 window by calling the form2’s show method. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7529/2900/1600/PassData.3.jpg"&gt;&lt;/a&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center;" alt="" src="http://photos1.blogger.com/blogger/7529/2900/320/PassData.3.jpg" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2 class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;The Properties Approach&lt;/h2&gt;&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;span style="font-family:Times New Roman;"&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Properties allow clients to access class state as if they were accessing member fields directly, while actually implementing that access through a class method. In this method we are going to add one property to each form. In form1 we are going to use one property for retrieving value from the textbox and in form2, one property to set the label’s text property. Then, in form1’s button click event handler we are going to instantiate form2 and use the form2’s property to set the label’s text.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;h2 class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;The Delegates Approach&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style=";font-family:Times New Roman;font-size:100%;"  &gt;&lt;/span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;Technically, a delegate is a reference type used to encapsulate a method with a specific signature and return type. You can encapsulate any matching method in that delegate. Here we are going to create a delegate with some signature and assign a function to the delegate to assign the text from textbox to label.&lt;/span&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2 class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Winding up...&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;" align="left"&gt;&lt;span style=";font-family:verdana;font-size:85%;"  &gt;These four approaches are very simple in implementing data passing between forms. There are also other methods available in accomplishing the same. Source code for the methods I stated above is given at the top for download. It is time for you to put your thinking cap and find other ways of doing this. Happy Coding!!!&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin: 0in 0in 0pt;" align="left"&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/useritems/pass_data_between_forms.asp"&gt;&lt;span style=";font-family:verdana;font-size:78%;"  &gt;For source code and further reading...&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style=";font-family:'Times New Roman';font-size:12;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;color:blue;"   &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;/span&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;span style="font-size:0;"&gt;&lt;pre class="MsoNormal" style="margin: 0in 0in 0pt;" lang="cs"&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;span style="font-size:0;"&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;span style="font-size:0;"&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;span style="font-size:0;"&gt;&lt;span style=";font-family:'Courier New';font-size:10;"  &gt;&lt;span style="font-size:0;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="color:blue;"&gt;&lt;span style="font-size:0;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/30721886-115217204803280719?l=csharpnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharpnet.blogspot.com/feeds/115217204803280719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=30721886&amp;postID=115217204803280719' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/115217204803280719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/30721886/posts/default/115217204803280719'/><link rel='alternate' type='text/html' href='http://csharpnet.blogspot.com/2006/07/passing-data-between-forms-winforms.html' title='Passing Data Between Forms - WinForms'/><author><name>Thiagu</name><uri>http://www.blogger.com/profile/17888457107965047422</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
