Getting Started with C# Application Development using SharpDevelop

in #utopian-io8 years ago (edited)

In just a few minutes a new programmer can easily create an new application in C# by using the Microsoft .NET Framework and a SharpDevelop IDE.

What Will I Learn?

How to Create a C# Form for Windows
How to Add Components to a C# Form

Requirements

  • .NET Framework
  • SharpDevelop IDE

Difficulty

  • Basic

Tutorial Contents

  1. Getting Ready for C#
  2. A Very Simple C# Application
  3. Adding Components to a C# Form

Curriculum

Getting Started with C# Application Development using SharpDevelop

C# (or C Sharp) is one of .NET family and is becoming increasingly popular amongst programmers. Its programming style is largely based on C++ but with a fair amount of Java thrown in for good measure. This means that anyone with a background in either language will not find it too difficult to migrate to C# and, in fact, anyone completely new to programming will not find the learning curve to be too steep.

However, the potential C# programmer will need to carry out a couple of tasks before they can actually start programming.

Getting Ready for C#

Before creating a new C# application the programmer requires two things:

  • The Microsoft .NET Framework
  •   #develop (short for SharpDevelop) - an open source IDE for C# 

The Microsoft .NET Framework is the architecture within which Windows applications can operate. It is pre-installed in some versions of Windows but the most up to date version is freely available from Microsoft ASP.NET Essential Downloads.

Once the Microsoft .NET Framework is installed then the programmer can install SharpDevelop IDE with which they can develop their applications. Once the programmer has installed the IDE then they are ready to create their first C# application – in this case a simple Windows form.

A Very Simple C# Application

The SharpDevelop IDE will create a simple blank form for the programmer, and this simplest of C# applications will consist of:

  • Details of any classes to be included
  • A new class extending the Windows form class

Therefore the code to display an empty form will be something like:

using System;
using System.Windows.Forms;
public class MainForm : Form {
public static void Main() {
Application.Run(new MainForm());
}
public MainForm() {
}
}

It’s worth noting at this point that C# allows partial classes. These enable the programmer to use multiple files for the class definition. However, whichever method is uses, if the C# is built at this point then it will display a simple, blank form. The Next stage is to add components to the form.

Adding Components to a C# Form

When it comes to adding components to a form the programmer must:

  • Define the components to be added (such as labels, text boxes and buttons)
  • Define the location of each component on the form
  • Add any text for the buttons and labels
  • Add any functionality for components (such as buttons)
  • Make the components visible

The resulting code is slightly more complex (but still very simple):

using System;
using System.Windows.Forms;
using System.Drawing;
public class MainForm : Form {
//Define variables for the components
private Label lblText;
private TextBox txtIP1;
private TextBox txtIP2;
private Button cmdDoCalc;
public static void Main() {
Application.Run(new MainForm());
}
public MainForm() {
//Set the title of the form
this.Text = "The Simplest C# Application";
//Create the components
this.lblText = new Label();
this.txtIP1 = new TextBox();
this.txtIP2 = new TextBox();
this.cmdDoCalc = new Button();
//Set the position of the component
txtIP1.Location = new Point(0,0);
txtIP2.Location = new Point(0,25);
cmdDoCalc.Location = new Point(0,50);
lblText.Location = new Point(0,75);
//Set the text and the action of the button
cmdDoCalc.Text = "+";
cmdDoCalc.Click += new EventHandler(this.DoCalc);
//Add some text to the label
lblText.Text = "Hello World!";
//Show the components
this.Controls.Add(txtIP1);
this.Controls.Add(txtIP2);
this.Controls.Add(cmdDoCalc);
this.Controls.Add(lblText);
}
//The action for the button
public void DoCalc(object Sender, EventArgs e) {
lblText.Text = Convert.ToString (
Convert.ToDouble(txtIP1.Text) +
Convert.ToDouble(txtIP2.Text)
);
}
}

If the form is built now then it will show:

  • Two text input boxes
  • A button which, when clicked, will add the contents of the boxes and display the result

And so from this humble start the C++ or Java programmer can quickly move on to produce much more complicated C# applications.

Summary

The new C# programmer needs two things:

  • The Microsoft .NET Framework
  • SharpDevelop IDE (Integrated Design Environment)

Both of which are freely available from the web sites. The IDE will create a blank form for the programmer who then extends the basic form class, adding any required components and actions. In just a few minutes they will have a simple, but effective, form that can be further extended quickly and easily by the programmer.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because you only explained these codes without putting them to work. An execution(RUN) was expected from this tutorial.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.076
BTC 64056.44
ETH 1676.52
USDT 1.00
SBD 0.41