You are on page 1of 6

Open Microsoft Visual Studio IDE

1. Go to File  New  Project


2. In that Go to Visual C#  Web  ASP.NET Web Application
3. You can give any name your want and click on OK. You will be redirected to a page
Default.aspx
4. In that page in the bottom, click on the design button.
5. Now in the left side you find a button Toolbox. Click on that button. Now you see the
tools- Standard(Pointer, Label, Textbox, etc), Data, Validation etc.
6. You can find it in View also.(press Alt+v). On top of toolbox, its better if you select auto
hide off.

Now have the picture of calculator in your mind. If you do so it is very is to implement your
views with the support given by .NET IDE. What you have to do is just drag and drop.

As far as my view is considered, I want have

(i) A Text box to see the values entered and for the output
(ii) Buttons for numbers and operations(+,-,/,*)

That’s all I need. you can add others tools also like link labels.

Now you are in the Design part. In this part you will be creating the view by simply
dragging the tools on to the design page. And you can write a text directly on the page by
clicking on the spot wherever you want to write.
And now you can drag from the tool box and drop it on the design page. See I dragged the text
box and of course I changed its size. When you click on the text box you will find small boxes
on top of the box to change the size.

You can move the box to right, by placing the cursor before it( don’t select it) and press space or
tab.

Similar way I dragged the buttons also. You need not drag all the buttons one by one. You can
copy and paste the buttons there itself.

Now select a ‘button’ and do right click, and click on ‘properties’.

You can see the properties of button on the right side in Properties Window. If you don’t find go
to View and click on Properties Window.

In that window you can now the details of options alphabetical, events, properties by simply
placing the cursor on the icons.

For Text Box, since you are going to give input using buttons, go to properties of Text box and
change read only option to true.

In properties go to Text and change the text to numbers and symbols.

Now give the values (I mean change the text) to all the buttons.
Now the work is, if you click on a button that value should appear in the text box.

To do this, first double click on the button, and write respective code.

Example:

When I click on the button numbered 1, that number should appear in the text box.

So if I double click on the button I will be redirected to Default.aspx.cs and Straight away my
cursor will be placed in a function button_click(); where I need to write the code when I clicked
on that.

So my code will be
TextBox1.Text = "1";

Here TextBox1 is id of the textbox created.

note: when u click on 2 after 1, it should show 12. So , u need to append here.

For appending you can use ‘+’;

Example: ‘x’+’y’ will be “xy”;

Now the work flow I am expecting from you is

1. Whenever a user clicks on any operators, the value in textbox, operator should be saved.
2. And soon after he gave the next value and pressed any other button except numbers it
should do the previous operation and should be ready to go for next operation.
3. Same as calculator in your system
4. Add trigonometric, logarithmic and other scientific calculator operations also.

U can find these trigonometric operations built in the .net IDE. In Math class.

Example: x=Math.Sin(45);

That’s all .

How to execute:

1. F6 (Build  Build Solution) to build a solution file ( which has all the details about your
site)
2. The same you can use for checking the errors.
3. F5 ( Debug  Start Debugging) to run the code (will be displayed in your default
browser).

Deadline: 10-03-2011, 9AM.

Suggestion: You can try the same calculator to develop a system application

Goto New  project  Visual C#  Windows  Windows Forms Application.

After completion Goto Build Publish. You will be having your own setup file for calculator.
You can install in any system.
//Example code for default.aspx.cs page:

//in my desgine Button1 is for 1


//in my desgine Button2 is for +
//in my desgine Button3 is for =

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Calc
{
public partial class Default : System.Web.UI.Page
{
//global data
int pre_value; //to store previous value
char operation; //to know the operation. I have not used. But u require this.
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
//this is code for button named 1
TextBox1.Text = TextBox1.Text + "1";
}

protected void Button2_Click(object sender, EventArgs e)


{
//this is code for button named "+"
pre_value = Convert.ToInt32(TextBox1.Text);
operation = '+';
}

protected void Button3_Click(object sender, EventArgs e)


{
//this is code for button named "="
//now i know only one operation(+) is there in my example.
//so directly i am operating the add operation.
//you have to code for all operations using operation variable
TextBox1.Text = (Convert.ToInt32(TextBox1.Text) + pre_value).ToString();
}
}
}
//flow of operation:
//when user clicked a number button that button will be added to text box using
//statement TextBox1.Text = TextBox1.Text + "1";
//its operation of strings.
//when user clicked an Operation button:
//You have to store the value in textbox in some variable, that operation in one char variable
//when user clicked "=" button you have to do the opearion that is in char variable on present
value in text box with the previous value u stored.

You might also like