is trick to build and compile a C# Windows Forms application without
using Visual Studio IDE.
This approach is not recommended but this is something you should
know when you have
only command line interface and want to create some handy utilities. If you do not have a Visual Studio IDE, you
may download Express versions for free from MSDN website.
In this article, we are going to
create a sample Windows Forms application that will create a Form with a
Button control and click on the button will display a text using a
1. .NET Framework 2.0/3.5
2. Visual Studio 2008/2005
Programatically Event Handling Knowledge
up Notepad and write C# Program like below. As you can see from this
code, we first import System and System.Windows.Forms namespaces.
//Declare Name Spaces
// Display Controls on Form Programatically
// Create Constuctor of Class
// Global Variables
public TextBox t1;
public Button b1;
//Suspend the layoutl logic
//Set Properties of Button a
b1= new Button();
b1.Location =new System.Drawing.Point(30,40);
b1.Text = "Click Me";
//Add handler to Button
b1.Click += new System.EventHandler(b1_Click);
//Set Properties of Text Box
t1 = new TextBox();
t1.Location = new System.Drawing.Point(20,20);
//Add Conponents on form
//Give Form title
this.Text = "GUI Without VS";
//Resume the layout
public void b1_Click(Object Sender,EventArgs e)
MessageBox.Show("Hello you Clicked Me");
//Now every thing is done Lets Build The Main method
public static void Main()
Step 2. Compilation
Save the text file and name it GUITest.cs.
Now open Cmd and change directory to C:\Program Files\Microsoft Visual Studio 8\VC\
cd C:\Program Files\Microsoft Visual Studio 8\VC\
then enter the command to compile the exe here target is type of output we want and /out is used to create our output file.
Command looks like this here you want to make sure the path of Exe and .cs files matches on your machine.
csc.exe /target:exe /out:c:\Users\Kirtan\Desktop\GUITest.exe C:\Users\Kirtan\Desktop\GUiTest.cs
Now if you go to your desktop, you will see GUITest.exe is there. Just double click on that and run it.
The article explained how to create Windows applications using C# compiler from command line without using Visual Studio IDE.