Programación > Visual Studio.Net
Calculadora en ASP .net .aspx Visual Estudio.net
(1/1)
Alittaxx:
Calculadora en ASP .net .aspx Visual Estudio.net
Se me pidio realizar una calculadora, pero esta solo debe tener un text box en donde se puedan ingresar los numeros realizar las operaciones y mostrar el resultado,ademas que debe mostrar los operadores , sin numeros.
Por favor ayuda por que no se como hacerlo, lo e buscado, pero en todas lo realizan con 3 text box.
Walkarton:
Hola, yo tengo una idea, pero no llego a redondiar, podrias dar mas datos, por ahi una foto del formulario de la calculadora con los elementos que se pueden usar...
Saludos
anonimus18:
1. En la Sección de Codigo Abierto hay varios ejemplos de como hacer calculadoras
Ej: You are not allowed to view links.
Register or Login
2. Aquí te dejo un ejemplo en C#...
Calculadora.Aspx
Código: You are not allowed to view links.
Register or Login<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Calculadora.aspx.cs" Inherits="Calculadora" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Calculadora en C# By alex19910218 HAJR</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div style="z-index: 101; left: 11px; width: 8px; position: absolute; top: 20px;
height: 216px">
<table>
<tr>
<td align="right" colspan="6">
<asp:TextBox ID="txtresultado" runat="server" ForeColor="Red"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 17px">
</td>
<td style="width: 19px">
</td>
<td style="width: 22px">
</td>
<td style="width: 18px">
</td>
<td style="width: 9px">
<asp:Button ID="btnborrar" runat="server" OnClick="btnborrar_Click" Text="Borrar" /></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 17px">
<asp:Button ID="btnsiete" runat="server" OnClick="btnsiete_Click" Text="7" /></td>
<td style="width: 19px">
<asp:Button ID="btnocho" runat="server" OnClick="btnocho_Click" Text="8" /></td>
<td style="width: 22px">
<asp:Button ID="btnnueve" runat="server" OnClick="btnnueve_Click" Text="9" /></td>
<td style="width: 18px">
<asp:Button ID="btndividir" runat="server" Text="/" OnClick="btndividir_Click" /></td>
<td style="width: 9px">
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 17px">
<asp:Button ID="btncuatro" runat="server" OnClick="btncuatro_Click" Text="4" /></td>
<td style="width: 19px">
<asp:Button ID="btncinco" runat="server" OnClick="btncinco_Click" Text="5" /></td>
<td style="width: 22px">
<asp:Button ID="btnseis" runat="server" OnClick="btnseis_Click" Text="6" /></td>
<td style="width: 18px">
<asp:Button ID="btnmultiplicar" runat="server" Text="*" OnClick="btnmultiplicar_Click" /></td>
<td style="width: 9px">
<asp:Button ID="btnraizcuadrada" runat="server" OnClick="btnraizcuadrada_Click" Text="sqrl" /></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 17px">
<asp:Button ID="btnuno" runat="server" OnClick="btnuno_Click" Text="1" /></td>
<td style="width: 19px">
<asp:Button ID="btndos" runat="server" OnClick="btndos_Click" Text="2" /></td>
<td style="width: 22px">
<asp:Button ID="btntres" runat="server" OnClick="btntres_Click" Text="3" /></td>
<td style="width: 18px">
<asp:Button ID="btnrestar" runat="server" Text="-" OnClick="btnrestar_Click" /></td>
<td style="width: 9px">
<asp:Button ID="btnexponencial" runat="server" OnClick="btnexponencial_Click" Text="1/x" /></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 17px">
<asp:Button ID="btncero" runat="server" OnClick="btncero_Click" Text="0" /></td>
<td style="width: 19px">
</td>
<td style="width: 22px">
<asp:Button ID="btncoma" runat="server" OnClick="btncoma_Click" Text="," /></td>
<td style="width: 18px">
<asp:Button ID="btnsumar" runat="server" OnClick="btnsumar_Click" Text="+" /></td>
<td style="width: 9px">
<asp:Button ID="btnigual" runat="server" OnClick="btnigual_Click" Text="=" /></td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
--- Fin del código ---
Calculadora.aspx.cs
Código: You are not allowed to view links.
Register or Loginusing System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//
using System.Collections.Generic;
using System.Drawing;
public partial class Calculadora : System.Web.UI.Page
{
//------------Variables------------
//Suma
public static string su;
public static int suma;
//Resta
public static string res;
public static int restar;
//Multiplicación
public static string mul;
public static int multiplicar;
//División
public static string div;
public static int division;
//Igual
public static string igu;
public static int igual;
//Total
public static int total;
//Raiz Cuadrada
public static double raiz;
//Exponenciación
public static double expo;
//---------------------------------
protected void Page_Load(object sender, EventArgs e)
{
}
//Cero
protected void btncero_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 0;
}
//Uno
protected void btnuno_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 1;
}
//Dos
protected void btndos_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 2;
}
//Tres
protected void btntres_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 3;
}
//Cuatro
protected void btncuatro_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 4;
}
//Cinco
protected void btncinco_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 5;
}
//Seis
protected void btnseis_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 6;
}
//Siete
protected void btnsiete_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 7;
}
//Ocho
protected void btnocho_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 8;
}
//Nueve
protected void btnnueve_Click(object sender, EventArgs e)
{
this.txtresultado.Text += 9;
}
//Coma(,)
protected void btncoma_Click(object sender, EventArgs e)
{
this.txtresultado.Text += ",";
}
//Sumar
protected void btnsumar_Click(object sender, EventArgs e)
{
su = this.txtresultado.Text;
suma = Convert.ToInt32(su);
this.txtresultado.Text = "";
}
//Igual
protected void btnigual_Click(object sender, EventArgs e)
{
igu = this.txtresultado.Text;
igual = Convert.ToInt32(igu);
this.txtresultado.Text = "";
if (suma > 0)
{
total = suma + igual;
this.txtresultado.Text = Convert.ToString(total);
borra();
}
else
if (restar > 0)
{
total = restar - igual;
this.txtresultado.Text = Convert.ToString(total);
borra();
}
else
if (multiplicar > 0)
{
total = multiplicar * igual;
this.txtresultado.Text = Convert.ToString(total);
borra();
}
else
if (division > 0)
{
total = division / igual;
this.txtresultado.Text = Convert.ToString(total);
borra();
}
}
//Raiz Cuadrada
protected void btnraizcuadrada_Click(object sender, EventArgs e)
{
raiz = Convert.ToDouble(this.txtresultado.Text);
this.txtresultado.Text = "";
this.txtresultado.Text = Convert.ToString(Math.Sqrt(raiz));
}
//Restar
protected void btnrestar_Click(object sender, EventArgs e)
{
res = this.txtresultado.Text;
restar = Convert.ToInt32(res);
this.txtresultado.Text = "";
}
//Borrar
protected void btnborrar_Click(object sender, EventArgs e)
{
borra();
this.txtresultado.Text = null;
}
//Multiplicación
protected void btnmultiplicar_Click(object sender, EventArgs e)
{
mul = this.txtresultado.Text;
multiplicar = Convert.ToInt32(mul);
this.txtresultado.Text = "";
}
//Dividir
protected void btndividir_Click(object sender, EventArgs e)
{
div = this.txtresultado.Text;
division = Convert.ToInt32(div);
this.txtresultado.Text = "";
}
//Exponencial
protected void btnexponencial_Click(object sender, EventArgs e)
{
expo = Convert.ToDouble(this.txtresultado.Text);
this.txtresultado.Text = "";
this.txtresultado.Text = Convert.ToString(Math.Pow(1,expo));
}
//Procedimiento para Borrar las variables
public void borra()
{
//Suma
su = null;
suma = 0;
//Resta
res = null;
restar = 0;
//Multiplicación
mul = null;
multiplicar = 0;
//División
div = null;
division = 0;
//Igual
igu = null;
igual = 0;
//Total
total = 0;
//Raiz Cuadrada
raiz = 0;
}
}
--- Fin del código ---
Saludos!!!
vart001:
intento depurar el codigo pero solo sale una pantalla en blanco..
alguien saber porque susede esto?
edito***
ya funciono! exelente ejemplo, he buscado por todo internet y solo en CPH encontre..
Navegación
Ir a la versión completa