Library code snippets
Getting Started With C#
This example is to get you started using C# in Visual Studio.NET. It is intended to be used as your first program to test your Visual Studio .NET installation, and to start finding your way around in VS. I have left out many of the steps, assuming that you have used previous generation tools. The screen shots are given, to help you find your way around the screen. I have given instructions for changing names which the wizard has given you. This is not to convince you to use my naming conventions, but to convince you not to use what the wizard gives you.
Create a new C#, Windows Application and call it Calculator.
Click the Form in the Form Designer to select it. In the Properties Window, change the text property to Calculator. This will change the name in the title bar of the Form.
In the Solution Explorer, right click on Form1.cs and rename it as FCalculator.cs. Also go through the source code and change all instances of Form1 to FCalculator.
Add 3 TextBox and 4 Button Controls to the Form. Use the Format menu to arrange the controls on the Form. For the 3 TextBox controls, clear the Text property, and change the (Name) properties to textBoxOp1, textBoxOp2, and textBoxAns. Change the text on the buttons to "+, -, *, & /". Change the (Name)s to "AddButton, SubtractButton, MultiplyButton, and DivideButton.
Double click each button to create its event handler, and add the code.
private void AddButton_Click(object sender, System.EventArgs e)
{
double dAns;
dAns = double.Parse( textBoxOp1.Text ) + double.Parse( textBoxOp2.Text
);
textBoxAns.Text = dAns.ToString();
}
private void SubtractButton_Click(object sender, System.EventArgs e)
{
double dAns;
dAns = double.Parse( textBoxOp1.Text ) - double.Parse( textBoxOp2.Text
);
textBoxAns.Text = dAns.ToString();
}
private void MultiplyButton_Click(object sender, System.EventArgs e)
{
double dAns;
dAns = double.Parse( textBoxOp1.Text ) * double.Parse( textBoxOp2.Text
);
textBoxAns.Text = dAns.ToString();
}
private void DivideButton_Click(object sender, System.EventArgs e)
{
double dAns;
dAns = double.Parse( textBoxOp1.Text ) / double.Parse( textBoxOp2.Text
);
textBoxAns.Text = dAns.ToString();
}
Related articles
Related discussion
-
how to select multiple files at a time using Ctrl+select and upload the attachments in C# .Net 1.0?
by vasanta (0 replies)
-
Help please for student
by mandy130 (0 replies)
-
Loop help needed
by BKRoberts (5 replies)
-
Problem after strong naming an assembly
by rinkurathor1 (0 replies)
-
Regarding User control creation in C# .Net(Windows Application)
by porchelvi (0 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
Really it is very much helpfull to me
Thanking you,
Expecting similar classes and bit higher version
S.Krishna
kri_it2003@yahoo.com
Really it is very much helpfull to me
Thanking you,
Expecting similar classes and bit higher version
S.Krishna
kri_it2003@yahoo.com
This thread is for discussions of Getting Started With C#.