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
-
Query Tool to Excel using C# and .NET
by BarbaMariolino (1 replies)
-
looking for help on asp
by cladironbeard (2 replies)
-
Socket Programming in C# - Part 1
by graumanoz (23 replies)
-
LINQ in Action
by naser1 (0 replies)
-
Creating a Windows Service in VB.NET
by Templario55 (107 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
Events coming up
-
Aug
28
St. Louis Day of .NET
St. Charles, United States
Technical conference with be 2 full days of content with over 40 sessions from local and national speakers, with topics such as:•.NET languages: C#, VB.NET•Technologies: WPF, Silverlight, WCF•Development tools: Visual Studio, TFS, Expression Blend
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#.