Pages

Tuesday 3 March 2015

Integrating C# .NET with Embedded System:Chapter-1

OVERVIEW

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by Ecma and ISO.C# was developed by Anders Hejlsberg and his team during the development of .Net Framework.


C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages to be used on different computer platforms and architectures.



The following reasons make C# a widely used professional language:


·         Modern, general-purpose programming language.

·         Object oriented.

·         Component oriented.

·         Easy to learn.

·         Structured language.

·         It produces efficient programs.

·         It can be compiled on a variety of computer platforms.


·         Part of .Net Framework.

Getting started

Creating a new visual studio C# project:
Once Visual Studio is running the first step is to create a new project. Do this by selecting New Project from the File menu. This will cause the New Project window to appear containing a range of different types of project. For the purposes of this tutorial we will be developing a Windows Forms Application so make sure that this option is selected.

CREATING NEW PROJECT

The first thing you do when you want to create a new application is to create a NEW PROJECT.

This can be done from start page.

New project created from the NEW PROJECT window:

Then the “NEW PROJECT” window will appear.

In this window you will select an appropriate template based on what kind of application you want to create, and a name and location for your project and solution.


The most common applications are:
  •        Windows form application.
  •        Console application.
  •      WPF application
  •       ASP.NET web application.
  •      Silverlight application. 
Select WINDOWS FORMS APPLICATION.

TOOL BOX

When you select WINDOWS FORM APPLICATION, you will get FORM DESIGN WINDOW,it is used to design USER interface by making use of TOOLBOX on the left side of window,

The TOOLBOX contains all the necessary controls, etc. You need to create a user interface by making use of these controls as shown in figure below.



In order to use these controls, just drag and drop it on to your Design forms, as shown in figure.



Figure shows TOOLBOX and DESIGN FORM:


The following screenshot shows, making use of these toolbox controls for designing the user interface on DESIGN FORM.




PROPERTIES WINDOW


Each TOOLBOX we have used on our form has many properties that we can set. This is done by using Properties window. We can find the property window on the right bottom side of your project.


BUILD AND DEBUGGING TOOL

The visual studio has lots of Build and Debugging Tools,


BUILD MENU:


Below we see the Build menu. The most used Build tool is BUILD SOLUTIONS.


DEBUG MENU:


In order to RUN or DEBUG your windows form we make use of DEBUG TOOLs. The most used debug tool is START DEBUGGING.it can be find the shortcut for this on the top of your visual studio windows.      



                                                                                                                                                                                                     

Windows programming


When creating ordinary windows form application, we can select between the following:



·         Windows form Application

·         WPF application




HELLO WORLD


We start by creating traditional “HELLO WORLD” application using Windows Form Application is shown below. Thevisual studio UI shown below.



In this application we make use of simple textbox and Button(Button name is changed to Submit in the properties) when we click on submit the “HELLO WORLD ”massage will be displayed in the Textbox.

The OUTPUT  of this form as shown below:
THE CODE IS AS FOLLOW:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication9
{
publicpartialclassForm1 : Form
    {
public Form1()
        {
            InitializeComponent();
        }

privatevoid textBox1_TextChanged(object sender, EventArgs e)
        {

        }

privatevoid button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "HELLO WORLD";//displaying hello worldin the textbox.
        }
    }
}