Getting Started with myRio
Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a tutorial on new board and as you can see in the title, this new board is named as Myrio. So, today, we are gonna have a look at getting started with Myrio. NI myRIO is a combination of dual-core ARM Cortexâ„¢-A9 real-time processing and Xilinx FPGA customizable I/O. It is specially designed for engineering students by National Instruments and is a cheap as well as an awesome piece for building your dream projects.
Recently I got a chance to work on this NI Myrio board and I really enjoyed while working on them as they not only awesome but also easy in programming. Moreover, because of its awesome speed you can ask it to do any kind of embedded work. You can read more about myRio on the Official Site of National Instruments. Today, I am not gonna design any project on this NI myRio board, instead I am gonna give you a quick overview of getting started with myRio. So, what's the delay :P Let's have a look at getting started with myRio board.
Getting Started with myRio
- I ordered my myRio board about a month ago and I got it delivered within 10 days.
- Below are the items which I have received in the myRio box:
- myRio board itself.
- USB Cable to plug myRio board with computer.
- Three CDs which contains the software.
- A manual having the instructions for myRio use.
- If you have also ordered the myRio board then you must have also received the same things in the box.
- Now first of all, what you need to do is to arrange a 12V adapter for power up your Myrio board.
- The one I have used is of 12V and 1.5A.
Note:
- There are different models of myRio available online and the one I received is myRio 1900, which has the Wifi functionality in it.
- There's also another myRio board called myRio 1950 which doesn't has the WiFi functionality in it so if you got that one then there's no need to be worried as both boards works exactly the same so if you have any other model then still you can follow today's tutorial as its valid for all myRio boards.
- Now I assume that you have arranged a 12V adapter and ready to plug it in your myRio board. :P
- So, why are you waiting ??? :P Simply plug you adapter in the myRio board and two lights on it will get on as shown in the below figure:
- So, you can see in the above figure that when I plugged the adapter in my myrio, the Power LED and the Status LED turned ON.
- After some time the status LED will turned OFF.
- Now next thing you need to do is to connect your USB cable with your computer from one side and with myRio from the other side.
- As soon as you connect the USB cable, the myRio will start installing the driver on your computer. It will take some time.
- Once the driver is installed, then a pop up window will open up as shown in below figure:
- Now, if you got this pop up window then it means your myRio driver has installed successfully.
- This window is giving you some information about your myRio board like mine is NI myRio 1900, yours could be 1950.
- Now next thing you need to do is to click the first button which says "Launch the Getting Started Wizard".
- Now when you click it, a new window will open up as shown in below figure:
- Now in the above window, it is showing the connected NI myRio device, if you can't see your device then click on the Refresh button.
- If your device is listed as mine then you need to press the Next Button.
- When you press the Next button a new window will pop up as shown in below figure:
- In the above window, you can change the name of your myRio board, if you want but I have left it as it is and clicked the Next button and below window opened up:
- Now finally we have reached the control window, from this window we are gonna control all the four LEDs labelled as LED0, LE1, LED2 and LED 3 and also gonna get notification for the button pressed and will also get values for X, Y and Z axis.
- IF your check your myRio board, rite now then you will see that LED2 and LED3 are ON now and you can see in above figure that LED2 and LED3 are green.
- Now you can click these buttons to turn your respective LED ON or OFF.
- Similarly when you press the button on your myRio board then this black small circle will go green.
- Moreover, if you change the orientation of your myRio board then its axes values will also change as it has built in gyroscope.
- You can check more detail on this below video:
So, that's all about getting started with Myrio. Today, we have seen how to get started with your new NI myRio board and also how to control the built in LEDs, button and gyroscope of myRio board. I hope now you can play a little with your myRio board. That's all for today. In the coming post, I am gonna discuss How to Configure NI myRIO on Wifi. So, till then take care and have fun !!! :)
How to use C# array
Hello everyone, hope you all are fine and having fun with your lives. In today's tutorial, we are gonna have a look at How to use C# Array. C# array is quite a simple concept but students normally got confused while using C# array that's why I am gonna explain it in a detail. C# array is used to store similar data in a single variable. Let me explain this with an example. Suppose you have 10 integer variables then what you need to do is to save all of these 10 variables in separate C# Int variables which will not only increase the size of your code but will also make it quite complex. So, instead of creating 10 separate C# Int variables you can simply create a single C# array and can add all of them in it.
Let's take an example for C# arrays from normal life. You can consider a classroom of a school as an array and its elements will be all the students in that class. :) So, if there's a 9th class then all the students in 9th class are the members of that 9th class array but the students of 10th class will not be members of 9th class array, instead they will be members of 10th class array. :P Now, a question arises that how to call a single member of any array then in that case for class arrays we have roll numbers. so you can call any member of 9th class by calling his roll number. Similarly, in C# array we have indexes for each member of an array and we can call individual members using these indexes, we will have a look at it below. The members of any arrary are normally called the Elements of that array. So, let's get started with C# arrays.
You may also like:
How to use C# Array ???
- As I explained earlier, C# Array is used to store similar variables in it. So, instead of using individual variables, we can simply add all those similar variables in a single array.
- So, an array is something as shown in below figure:
FirstArray[3] = {Element1, Element2, Element3};
- Now the above array has a name FirstArray and it can has maximum three members in it which is shown in these [ ] brackets.
- After that we have inserted the three members in it separated by commas.
- Now, if I want to access the individual members of this C# Array then I have to call them by their indexes.
- C# Array assigns an index to each of its elements and these indexes start from 0.
- So, the first element of each C# Array is always 0.
- So, if I call the 0th member of C# array then it will give me the first element of that array.
- Let's see how to call each of them:
- FirstArray[0] = Element1;
- FirstArray[1] = Element2;
- FirstArray[2] = Element3;
- So, that's how we can call any of the C# Arrays elements.
- Now let's design a simple projects and check it out in real example.
- So, create a simple C# project as we did in Introduction to C# Windows Forms.
- Now in this C# projects add some controls as we did in How to add C# Control in Windows Form.
- I have added two controls in it which are Button and a Text Box.
- The simple GUI is shown in below figure:
- So, now let's add an array in this GUI and then display its elements in the text box on button click.
- I am gonna add a C# string array so first of all, what I need to do is to declare the String C# array.
- In order to do so use the below code:
// C# Array Initializing
String[] students = new String[5];
// Initializing Complete
- So, you can see in the above code that I have initialized the C# array and in order to do so first of all, I have given the datatype of C# Array, which is String in the above case.
- After that, I have given the name of the C# Array which is students and the I have used new word to create the new instance of C# array.
- We will cover this new word concept in later tutorials but rite now its necessary to use it while initializing the C# array.
- Finally I have given the length of array which is 5 in our case, so you can add maximum 5 elements in this C# array.
- You can also make the length variable by simply removing this 5 as shown in below code:
// C# Array Initializing
String[] students = new String[];
// Initializing Complete
- Now this C# String Array is of variable length means you can add any kind of members in it.
- Now we have initialized our C# String Array, next thing we need to do is to add the values in it.
- One way of adding values to the C# array is as follows:
// Adding values to C# Array.
students[0] = "Zain";
students[1] = "Nasir";
students[2] = "Kamraan";
students[3] = "John";
students[4] = "Jack";
// Values added.
- Now you can see I have added five students in our C# Array and I have also assigned the index to each of them.
- "Zain" is saved at index 0 of students array so it will be the first element of C# array.
- That's one way of assigning values to C# array, here's another way:
// Adding values to C# Array.
String[] students = new String[5] {"Zain", "Nasir", "Kamraan", "John", "Jack"};
// Values added.
- In the above code, I have added the values in the initialization, both ways are correct.
- Now let's get the elements from this array and display them in the Text Box.
- In order to do so, use the below code:
txtClick.Text = students[0];
txtClick.Text += " , ";
txtClick.Text += students[1];
txtClick.Text += " , ";
txtClick.Text += students[2];
txtClick.Text += " , ";
txtClick.Text += students[3];
txtClick.Text += " , ";
txtClick.Text += students[4];
- One thing, I forgot to mention that I have changed the Name of the Button to ClickHere and Text of Button to Click Here. Moreover, I have changed the Name of Text Box to txtClick.
- Now your complete code will look something as shown in below figure:
- Now run your project and click the button and if everything goes fine then you will get results as shown in below figure:
- So, you can see all the elements of our C# Array are now displayed in the Text box.
So, that's all about the C# Arrays, I hope you guys have got something out of it. That's all for today, will meet you guys in the next tutorial. Till then take care and have fun !!! :)
How to use C# Comments ???
Hello everyone, I hope you all are fine and having fun. Today's tutorial is a quick one and is about how to use C# Comments. Comment is an important part of any programming language, although its not a directly part but they indirectly help a lot especially in complex projects.
I have also shared a tutorial on How to use comments in c++, you should read that post as well because I have explained few basic concepts in it. You guys are also welcome to give us feedback about this new C# tutorial series. If you have any suggestions about it then do let us know in comments.
How to use C# Comments ???
- Comments are simple documented text lines, completely ignored by the compiler and are used to explain or provide any additional information about coding.
- There are 3 types of comments available in C#, which are:
- Single Line Comments. ( Symbol used: // )
- Multi-Line Comments. ( Initial Symbol: /* Closing Symbol */ )
- XML Documentation Comments. ( /// )
- Now, let's have have look at each one of them in detail:
Single Line Comments
- Single Line Comments are used to comment any text in a single line, we have to place two forward slashes ( // ) and everything after that will be ignored by the compiler.
- Let's have a look at How to use Single Line Comments, in below figure:
- You can see in above figure, that I have used green comments above each block to explain my code i.e. mentioning 2D & 3D arrays, accessing array elements etc.
- Moreover, I have also used comments in front of the line i.e. displaying data at location 0, 0 etc. In this case, I am just explaining a single line.
Multi-Line Comments in C#
- We can also comment out multiple lines by using /* */ these symbols.
- Let's say, you don't want to execute some part of your code i.e. 100 lines, then it would be too difficult to place // these symbols in front of each line.
- In such cases, there's a need for Multi-Line Comments, here's an example:
- At the top of above code, you can see I have used Multi-Line Comments to give a simple introduction, here you can also add description of your project/code.
- Moreover, I have also commented out Console code, I just want output using For Loop and I have used Multi-Line Comments for that.
XML Documentation Comments
- In Microsoft Visual Studio, when you hover your cursor on any object then it pops up an info box.
- If you want to add any information in this pop up box then you need to use XML Documentation Comments, as shown in below figure:
- In the above code, I have created a new class named TEPClass, we will discuss classes later in detail, but for now just focus on XML comment above that class.
- In Program class, I have called TEPClass and now when I hover my cursor over it, you can see a pop up box appeared and it has that XML comment in it.
- I have placed a red arrow in front of it, here we can place a short description of our class.
Why we need to use C# comments ???
- Let's say you have to use some old code which you have designed a year ago.
- Now when you read your own code after a year, it will be difficult to understand.
- But if you have placed some check note (comments) for each command then you can easily understand it.
That's all for C# comments. I hope you guys have understood how & why we need to use C# Comments. In next tutorial, we will have a look at How to use If Loop in C#.
How to use C# String Variables
Hello friends, I hope you all are fine and having fun with your lives. In today's tutorial, we are gonna have a look at How to use C# String Variables in your C# Projects. In the previous tutorials, we have a look at How to use C# Int Variables and also have seen How to use C# Double Variable. So, now today we are gonna see how to use C# String Variable.
We have already discussed the variables in detail so I hope that you must have the idea of what variables are and if you don't then you must read the previous tutorials first. The code is also given below in the tutorial. So, let's get started with How to use C# String Variables:
How to use C# String Variables ???
- C# also supports string variable, a string variable can save anything in it in the form of characters.
- C# String variable can be of any length.
- So, let's design a small code to show how C# String works.
- First of all design a simple C# Project and add one button and one text box in it, as shown in below figure:
- Now change the Text of your Button to Click Here and Name of the button to ClickHere.
- Similarly change the Name of the text box to txtClick.
- We have already designed a similar project in How to use C# Int variables.
- Now that our project is added so now add the below code into it an your code will look something like:
- Now you can see in the above figure, that first I have created a string variable named webBlog.
- After that I have assigned it a value, because the variable is a C# string variable that's why it can save this string easily in it.
- After that I have simply displayed it in that text box.
- You must have noticed that this time we didn't have converted the value to string as we did in C# Double variable.
- Because our variable is already a string.
- Here's the complete code for copying:
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 Variables
{
public partial class Form1 : Form
{
string webBlog;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ClickHere_Click(object sender, EventArgs e)
{
webBlog = "www.TheEngineeringProjects.com";
txtClick.Text = webBlog;
}
}
}
- Now let's have a look at the results.
- So, run your project and then click on the button and the string will appear in the text box as shown in below figure:
- So that's how C# string variable works.
- Now you can save any kind of long strings in C# string variable.
- Now let's have a look at few of the string properties.
C# String Comparing
- Suppose you have two strings then How to compare them.
- So write your code as shown in below figure:
- Now you can see in the above code, I have used two C# String variables webBlog1 and webBlog2.
- I have given the same text to both of these C# string variables.
- Now after that I have used a small function called String.Compare() and it takes two C# string variables.
- After that it compares these two C# string variables and if they are same then it give 0 so that's why I have compared it to 0 means if the two C# string are equal then I have printed Both are equal otherwise not equal.
- So, that's how you can compare two C# String Variables.
- Here's the code for copy:
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 Variables
{
public partial class Form1 : Form
{
string webBlog1, webBlog2;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ClickHere_Click(object sender, EventArgs e)
{
webBlog1 = "www.TheEngineeringProjects.com";
webBlog2 = "www.TheEngineeringProjects.com";
if (String.Compare(webBlog1, webBlog2) == 0)
{
txtClick.Text = "Both are equal";
}
else
{
txtClick.Text = "Both are not equal";
}
}
}
}
Find subString in C# String
- Now suppose you have a long string and you want to find some small string whether its in the long string or not.
- Then you can use another function named as contain and the below example shows how to use this command:
- In the above figure, you can see that I have initialized a C# String variable and given it a string text.
- After that I have used the function String.Contain and checked a part in the string.
- So you can see the String is actually in the main string so it will give Its present in the string otherwise not present.
- So, run your project and then click the button and you will get something as shown in below figure:
- Now, you can see it has given that its present in the string.
- Here's the code for copying:
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 Variables
{
public partial class Form1 : Form
{
string webBlog1, webBlog2;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ClickHere_Click(object sender, EventArgs e)
{
webBlog1 = "www.TheEngineeringProjects.com";
if (webBlog1.Contains("Projects"))
{
txtClick.Text = "Its present in string";
}
else
{
txtClick.Text = "Its not present in string.";
}
}
}
}
Dividing a C# String
- So, now let's get something out of a string.
- Suppose in some project you have a very long C# string and you just want a part of that C# string.
- Then what you need to use is another string command which is webBlog1.Substring(4).
- So, have a look at the below code:
- Now in the above code you can see I have initialized a C# String variable and assigned it a value.
- After that, I have used second variable and then I have subString it by four characters and now run your project and click the button and you will get results as shown in below figure:
- So, you can see in the above string I have subString four characters in the initials and then the remaining is shown in the text box.
- So, that's how you can take any number of subString from the C# String.
So, that's all about C# String Variable. I hope you guys have learned something out of it. that's all for today. In the next tutorial we will learn more about C#. Till then take care and have fun !!! :)
How to use C# Double Variables
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to show you guys How to use C# Double Variable in your projects. In our previous tutorial, we have seen
How to use C# Int Variable and we have also discussed about the term Variables in detail. So, I am not gonna discuss it again and gonna come straight to our topic C# Double variable.
It's my second C# tutorial in the series of C# variables. In the coming tutorials, I will discuss the remaining C# variables in detail. I have also provided the project code below but I would suggest you to do it on your own so that you get most out of it. Moreover, you should also have a look at Introduction to C# Windows Forms and How to use C# Control in Widows Forms as I am gonna use two C# Controls in today's tutorial as I did in C# Int tutorial. So, let's get started with How to use C# Double Variable:
How to use C# Double Variable ???
- C# double variable can store 64 bit value in it.
- C# double can store integer as well as decimal values means you can save decimal values like 5.2, 3.1 as well as simple integers like 2, 5, 38 etc.
- C# double variable approximate value is ±5.0 × 10^-324 to ±1.7 × 10^308 as per Microsoft Official Page and its precision is 15-16 digits.
- So, first of all, design a new simple C# project as we did in Introduction to C# Windows Forms.
- I am not gonna design a new one, instead I am gonna use the same project as I did for C# Int Variable.
- So after creating a new project, add a Button and a Text Box in it as we did in How to add C# Controls in Windows form.
- Now, I hope that you are done with the front end of your C# Project and it will look something as shown in below figure:
- Now, let's add the code behind this form, so your code will look something as shown in below figure:
- Now if you have a look at it then you will see that its exactly the same code as we did for C# Int variables.
- But there's a slight difference that now all of the three variables a, b and c are double instead of int.
- That's why I have assigned decimal values to them where a = 2.5 while b = 2.6.
- C# Int variable can't use these value because these are not integers but double can easily handle them.
- So, now their result should be 5.1 which is again a double so that's why our third variable is also double.
- Here's the code for you to copy:
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 Variables
{
public partial class Form1 : Form
{
double a = 2.5;
double b = 2.6;
double c;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ClickHere_Click(object sender, EventArgs e)
{
c = a + b;
txtClick.Text = c.ToString();
}
}
}
- So, now run your project and then click the button and you will get results as shown in below figure:
- So, now you can see the value saved in C# double variable c was 5.1 which is now displayed in the Text Box.
So, that's all for today. I hope you guys have now understood How to use C# double variables in your projects. Thanks for reading. Have fun and take care. :)
How to use C# Int Variables
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a new tutorial on C# language which is How to use C# Int variables. In our previous C# tutorials, we have designed a small project in C# which prints Hello World on the screen. Then we have seen Introduction to C# Windows Form, in which we have designed our first Windows form in C#. Then we have added the C# controls on that windows form.
Now, in today's tutorial, I am gonna introduce you to a new concept which is variables. Variables are used in every programming language and without variables we can't design even a simple code. There are different types of variables available in C# language and today among these variables we are gonna focus on C# Int variables. If you are doing engineering then you must have the idea about integers. :P So, let's get started with C# Int variables. Before discussing the C# Int variables, let's first get an overview of variables.
What are Variables ???
- In any kind of programming projects, there's a need for storing some data in temporary memory spaces. these temporary memory spaces are named as variables.
- For example, I have a simple project in which I need to add 2+2 and then I need to add 2 more in the output.
- So, in that case what I am gonna do is first of all, I am gonna do the simple addition operation and will add the 2+2 and then I need to save the output which is 4 somewhere.
- So, I am gonna save this output 4 in a variable and then I am gonna add 2 more in that variable and again I will save the output which is 6 in another variable and then I can print it on the output.
- I think now its quite clear from the above example that variables are used to store data for a short time.
- Now data can be of any type, it could be an integer or some decimal value or it could be characters.
- So, that's why we have a long list of variable types in C#, which are as follows:
- Int (Integer)
- Double
- Float
- Char
- String
- Byte
- sByte
- Decimal
- Boolean
- You can read more about the variables from Microsoft Variables Page.
We will cover all these variables in separate tutorials one by one and we will see how to use them and to work with them. So, rite now we are gonna have a look at usage of C# Int variable, so let's get started with it.
How to use C# Int variables ???
- C# Int variables are used for storing integers values. Int is actually a short form of Integer.
- So, for example, you have to save 2 in some variable then as 2 is an integer so you can save it in C# Int variable.
- But if you have 2.05 value then its not an integer because it has a decimal part so you can't save this value in an integer so C# Int variable will only save integers in it.
- Let's design a simple example on C#, as we did in Introduction to C# Windows Forms.
- Now in this project, I am gonna add a Button and a Text Box and on pressing that Button I will print a variable in this Text Box.
- So, design a simple project, as shown in below figure:
- I have changed the name of the Button to "ClickHere" and the Text of the Button to "Click Here".
- I have also changed the Name of the Text Box to "txtClick".
- Now add some code in the Button as shown in below figure:
- In the above code, you can see first of all I have declared the C# Int variables, which are a, b and c.
- Then I have also assigned a value to a and b, which is 2.
- Now in the Button Click function, I have added both the C# Int variables and then saved their result in another C# Int variable named as c.
- Finally, I have printed that c variable in a text box.
- You must be wondering why I have used toString() because text boxes can only print strings but c is an integer so that's why I have converted that integer into string.
- I will discuss this string conversion in more detail later.
- Here's the code for you to use:
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 Variables
{
public partial class Form1 : Form
{
int a = 2;
int b = 2;
int c;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ClickHere_Click(object sender, EventArgs e)
{
c = a + b;
txtClick.Text = c.ToString();
}
}
}
- Now run your project and when you click the button then 4 will appear in the text box as shown in below figure:
So, I hope now you have got the idea How to use C# Int Variables. That's all for today. You should also have a look at How to use C# Double Variables. In the coming tutorial, we will discuss other C# variables just like this C# Int variable. Till then take care and have fun !!! :)
C# Tutorial
Hello everyone, I hope you all are fine and having fun with your lives. Today, I am going to share the list of all the C# tutorials, which I have posted on my blog till now. So, this post will be like a complete C# tutorial, which will have all the small and big C$ tutorials, I have posted on my blog. This list is quite small right now but I will post more C# tutorials soon and will add their links here. Actually, the C# tutorials are quite random on the blog so I am kind of compiling the list and pasting them all here so that readers won't get into much trouble finding them.
Till now, I have mostly posted the project on our blog in which I don't teach any language but provide you the code for that project. But now I have thought of writing complete series of tutorials in which I will teach different languages to beginners. I hope you will find them really helpful. So, the C# tutorial is the first tutorial in this series. I will post tutorials on other languages soon. So, let's get started with the C# tutorial:
C# Tutorial
Here are some very basic C# Tutorial, which are just for the beginners and if you know the basics of C# then I would suggest you to skip this section:
Basic Tutorials:
Note:
- You should also have a look at:
Loops in C#:
Important Concepts in C#:
C# Windows Form
Data Types in C#
Tutorials on C# Controls
Tutorials on C# Loops
Thanks for reading all those tutorials. If you still have any questions then ask in the comments and we will try our best to resolve your issues. Take care and have fun !!! :)
How to use Button in C# Windows Form ?
Hello everyone, I hope you guys are having fun with your lives. In today's tutorial, we are gonna have a look at How to use Button in C# Windows Form. In our previous tutorials, we have first discussed the Introduction to C# Windows Forms in which we have created our first C# Windows Forms Project. After that we have discussed How to add C# Controls in Windows Form, in which we have added different C# controls in that Windows form.
So, now we are gonna add back end programming in those Controls one by one. In today's tutorial, I am gonna add the code for the Buttons and you will see that it won't be any difficult to use them in your projects. So, let's get started with How to use Button in C# Windows Form.
How to use Button in C# Windows Form ???
- So, now we have two buttons in our C# Windows Form, so now First of all, let's change the text of first button from its Properties as shown in below figure:
- So, I have changed the text of Button1 to Click Here and I am gonna change the text of Button2 to Submit and they will now look like something as shown in below figure:
- Now you can see in the above figure that the Text on these buttons have changed to that which I have added in the Text section of their properties.
- Moreover, you must have also noticed that now their size has also increased, which I did by dragging the buttons.
- Now let's change the name of these buttons too so I am gonna change the Name of first button to ClickHere and that of second button to Submit.
- We can't add spaces in the Name of the Button.
- The Name Change for first button is shown in below figure:
- Now let's add the Click event for each of these buttons.
- Click event is the event which should happened when you press the button.
- So, now double click the first button and it will open up its code as shown below:
- Now you can see in the above code we have a function named ClickHere_Click, which is the click event function for first button.
- ClickHere is the name of the button which we changed above and _Click is the event. In simple words, this event will call on when the ClickHere Button is clicked.
- Next we have the arguments, which I am not currently gonna discuss here but we will have a look at them later and then we have these curly brackets { }, and that's where our code is gonna pasted for the click event of this button.
- So, add the below code into these brackets.
MessageBox.Show("Its a Click Here Button");
- Now when you pressed the Click Here Button then a sall message box will open up as shown in below figure:
- So, now you have seen, first we have added the Button then we changed its Text and Name and later we added the back end code in it so that it could perform an event on clicking.
- Now, I have added a small code in the Submit Button Click event and it looks something like this when you click it:
- So, that's all about how to use button in C# Windows Form.
That's all for today. Will meet you guys in the next tutorial on C#. Till then take care and have fun!!! :)
How to Add C# Controls in Windows Form ???
Hello everyone, hope you all are fine and having fun with your lives. Today, I am going to show you How to add C# Controls in your project. In our previous tutorial, we have seen an Introduction to C# Windows Forms in which we have created our first project and then we have discussed all about its different features like How to use Properties etc. and if you haven't read it yet then I would suggest you to read that one first as I am gonna continue from that tutorial onward.
So, I am assuming that you have read Introduction to C# Windows Forms and you have your first project created and ready to use. So, if you have dne exactly as I have shown in my previous tutorial then you have a for as shown in the below figure:
So, now we are gonna add some C# controls in this Windows form. So, let's get started with How to add C# Controls in it.
How to add C# Controls ???
- In our previous tutorial, we have discussed the Toolbox, which is available on the left side of your project.
- All the components in the toolbox are shown in the below figure:
- These are a lot of controls and we will cover most of them in our coming tutorials but rite now we are just interested in knowing How to add these C# Controls in Windows Form we created in our previous tutorial.
- So, the first C# Control I am gonna use is the Text Box, which is present in the Common Controls category.
- So, what you need to do is to drag this Text Box from toolbox to your Windows Form and then it will be placed on your Windows Form as shown in below figure:
- Now you can see in the above figure that our Form has a new C# Control in it which is a Text Box.
- Now when you select this Text Box then its Properties will open up in the Properties Section.
- From its Properties you can change many of its attributes.
- The two main attributes in Properties of any C# Controls are Name and Text.
- Name is the name of that Control with which we call it when we writing the code for that control.
- Text is the text which appears on that Control for user to view.
- Let me add another C# control on this Windows Form i.e. Button and then show you the difference between this Text and Name Property.
- So, drag a Button from the Toolbox and place it on this Windows Form as shown in below Figure:
- So, now we have two C# Controls on our Windows Form.
- Now I will select the Button and then its Properties will open up in the Properties Section and I am gonna change its Text to Click Here as shown in below figure:
- Now, lets see in the Form, what's written on the Button. :P
- Wow the magic happened :D and what we have written in the Text Section of the Properties of this Button has appeared on it.
- So, that's How the Text Property works. Whatever you written in the Text Section is appeared on that C# Control.
- The Name of Button Control is still button1 so whenever I am gonna call this button in the back end code I will use that Name.
- We are gonna do this in the next tutorial.
So, that's all for today. I hope you guys now have the idea How to add C# Controls in the Windows Form. In the coming tutorial, I am gonna add code behind each of these controls and will let you know How to use them. So, till then take care and have fun !!! :)
Introduction to C# Windows Forms
Hello everyone, hope you all are fien and having fun with your lives. Today, I am going to post a new C# tutorial in which we will have a Introduction to C# Windows Forms. Till now, we have seen Introduction to C# in which we have designed a console application in C# and after that we have discussed that project and write some code in it in First Code in C# Tutorial. So, till now we have an idea How to create a console application and how to run it easily.
I will continue with this C# console projects but first we have to discuss a little about C# Windows Forms. Microsoft Visual Studio is a very vast software so we can design different types of projects in it and also can use different languages. So, when talking about C#, we not only can design console applications but can also design C# Windows Forms in it. C# Windows Forms projects are much more easier than Console applications because in them you have a clear GUI in which you can drag and drop your components and can write the background code quite easily. So, let's get started with C# Windows Forms.
Introduction to C# Windows Forms
- First of all create a new project in Microsoft Visual Studio and in the settings select C# Windows Forms as shown in below figure:
- So, you can see in the above figure that all the steps are same as we did for creating a Console Application in Introduction to C# tutorial.
- But the only difference here is that instead of selecting Console application, we are selecting Windows forms Applications.
- Now, when you click OK then a new Project will open up as shown in below figure:
- So, now our project is ready and we can design any kind of project on it, but first let's discuss its features.
- If you have a look at it then you can see that it has three parts.
- The center part is where we have our Form1, we will change its name later.
- The on the left side we have a Toolbox which has all the components which can be used in this C# Windows Forms.
- On the right side, we have this Solution Explorer and below it we have Properties panel.
- So, let's discuss each of them separately.
Toolbox in C# Windows Forms
- Here's an image of all the components in the toolbox of C# Windows Forms:
- First of all there are categories like Common Controls etc and each of these categories has components in it which I have shown in detail by expanding these categories.
- So, these all controls can be used in C# Windows Forms and it depends on your application, which one you want to use.
- Most commonly used are buttons and text boxes etc which are in Common Controls section.
Solution Explorer in C# Windows Forms
- Here's an image of the Solution Explorer in C# Windows forms:
- This Solution Explorer shows all the files used in your C# Windows Forms Project.
- First of all, we have the Properties folder which has the AssemblyInfo.cs file, it contains the basics things about your project like name and copyrights etc.
- Then we have the References section, which has all the system library files.
- Next we have the Form1.Designer.cs file which contains out Form1 design.
- Finally we have the Program.cs file which has the back end code for our Form1.
- All the code we are gonna write for our C# Windows forms Project is gonna be add in this Program.cs file.
Properties in C# Windows Forms
- Here's an image of the Properties panel in C# Windows Forms:
- Now when you select any component on your C# Windows Forms then its properties open up.
- Rite now, I have selected the Main Form and its properties are appearing here.
- Now from these properties you can change many attributes of your project.
- Like for Form1, it says the name is Form1, so let me change the Text of it to something else as shown in below figure:
- Now you can see in the above figure that I have changed the Text of this Form1 to Introduction to C# Windows Forms.
- So, it will change the text of your Form to that as shown in below figure:
- Now you can see the Name of our Form has changed to the text which we have written in the Text section of its properties.
So, that's all about the Introduction to C# Windows form. In the coming tutorials, we are gonna add controls from the toolbox in this C# and then we will add some back end code to make them work. So, till then take care and have fun !!! :)