How to get data from text boxes using C Sharp:
we can get data from text boxes using c sharp.But there is some thing little tricky that we have to do.Text boxes only store data in form of text so it is needed to convert data into required for to use it. So let's see how to get and use data form text boxes in easy steps.
Step 1:
Start a new Windows form Application project.
Step 2:
Add tow text boxes and a button on your form.
It should look like as shown.
Step 3 ( getting Strings):
If we want to get String or text form text boxes we do not have to convert it. It's already have the text form.
we have to just write the following code and its ready.
string a = textBox1.Text;
string b = textBox2.Text;
Step 4:
If we want to out print these strings we have to use the following code.
MessageBox.Show(a + b);
Our program should out put the following message box.
Step 5( getting integers):
Now lets get some integers from the same text boxes and use them.
But now there is really need of converting them into integer variables.
to convert the strings to integers we have to use the following code.
int x = int.Parse(a);
int y = int.Parse(b);
Step 6:
To out print them we are going using following code.
MessageBox.Show(a +"
"+ b);
float f
= float.Parse(a);
float g = float.Parse(b);
Step 8:
To convert string to double we have to use the following block of code.
double d = double.Parse(a);
double c = double.Parse(b);
Step 9: After converting them we can use them where ever we want to use them.
I have tried to give you the best and simple tutorial, however if you are still confused i will be pleased to answer your concerns :)


No comments:
Post a Comment