ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software

C# Programming in Windows Form Application:

Updated on November 6, 2014

C# project development in VS 2013:

Open your IDE as Microsoft Visual Studio 2013

Go to menu bar, there will be File menu click on it. Then click on new option. After that you will see a new list menu from the list click on project. You can also use shortcut key for this simple task as (Ctrl+Shift+N).

Now there will be a window in-front of you. So click on templates from left side of the window. Now click on visual C#, after that direct click or choose Windows Forms Application. In the name field give a name to your project, as “Inserting text into label”. Now press OK button to proceed the tutorial for step 4.

Now you will see a form in-front of you, drag and drop three objects on it. Frist a button, second textbox and last a label. These all objects are available in Toolbox, which is left side of your visual studio 2013.

I am not going to change the objects default variables name, because you should recognize the objects during the coding or programming. Double click on button to start programming on it.

Following these steps we can develop projects for any kind of application when we want to design or develop them using C#.net. C#.net is very powerful tool and there are many libraries which are being used. By the help of libraries our problems solved easily. We can also use 3rd party libraries i.e Telerik library for C#.net. Using Telerik libraries we can develop more interactive applications. And these applications mostly depend on database. Because it is a problem how to retrieve data from the database and then show them as user wants. These dependency problems are being solved by Telerik library for C#.net programmers. Of-course it is costly product and we can just use it for one month trial.

Microsoft tool, C#.net
Microsoft tool, C#.net

Listing 1: Full program source code is below

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

namespace Inserting_Text_Into_Label
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] DataList = new string[10];
            bool ArrayStatus = false;
            for (int i = 0; i <= 9; i++)
            {
                if (DataList[i] == null & ArrayStatus != true)
                {
                    DataList[i] = textBox1.Text;
                    ArrayStatus = true;
                }
                if (DataList[i] != null)
                {
                    label1.Text += DataList[i] + Environment.NewLine;
                }
            }
        }
    }
}

Description

You don’t need to write these all code on your forms button event, you just need to write the listing 2 source code. Simple double click on your button after doing previous task during the C# project development in VS 2013, then copy listing 2 code and paste it on button event. I used Environment object for new line inside of the label. Because when in loop, the label will write first text so it needs a new line to write the second one. And Boolean is used to check the status of the work, is textbox and label are empty or not.

Using Arrays in C#.net Programming:

As we know that arrays are a list of data items, which have similar types. For example, we created an array you can see it in listing 1, there is a string array which is collecting a list of strings with size of 10. It means that this array will contain same or different 10 names of any item or something else as a word. There are types of arrays, as there is a list of primitive data types. i.e is int, char, string, float, etc.

In arrays there are elements and they started from 0. In listing 1, the array of string name is DataList which size is 10. it will start counting its elements from zero (0). Like this it's last element will be at 9 position in array and its first element will be 0 position in array.

Array elements

Array Elements positions in array
Array Elements positions in array

Listing 2: Button source code

     string[] DataList = new string[10];
            bool ArrayStatus = false;
            for (int i = 0; i <= 9; i++)
            {
                if (DataList[i] == null & ArrayStatus != true)
                {
                    DataList[i] = textBox1.Text;
                    ArrayStatus = true;
                }
                if (DataList[i] != null)
                {
                    label1.Text += DataList[i] + Environment.NewLine;
                }
            }        

Description of Array DataList

In Listing 1 and 2, i used to define the the program. But now at this time is should make you understand how an array stores data in his memory. I will try to define the same array which i used in these two listing to make you understand. As i defined it already the DataList array has 10 items storing capacity. So it will just store 10 items of any kind or type, But they should be string. I used kind or type just for words not for data types. It will store elements from zero position till 9th position.

For example:

DataList[0] = "Tomato";

DataList[1] = "Potato";

DataList[2] = "Ladyfinger";

DataList[3] = ......

so, you can see in the example we stored data in the array list. These all are same type in their characters as they are strings, but they are different from each other as they are words. I mean they have different meanings from each other also they are containing different length of characters in each string. We just stored 3 strings in the list from position zero till 2nd position in the array.

Result of C# Windows Form Application

Form Application
Form Application

Description:

In this article we discussed the arrays Boolean and three objects which were button, label and textbox. It is very easy to do programming in C# if you have basic information in previous languages as C++ and Java etc. As we used arrays declaration, it is same like in java. In java we declare the arrays same like this. Because arrays are being used as an object in C# and Java as well as. There are some similarities between Java and C# programming as they dependent on classes due to their object oriented structures. And kindly do your precious comments on my articles, what you learnt and what you expect from me more, do your comments on my articles.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.