Este es un proyecto de una Calculadora en WPF :
==================================================================
//Codigo archivo: MainWindows.xaml
=============================================================
<Window x:Class="CalculadoraWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CalculadoraWPF"
mc:Ignorable="d"
Title="Calculadora WPF" Height="400" Width="355">
<Grid>
<TextBox x:Name="Textbox_Screen" IsReadOnly="True" TextAlignment="Right" VerticalContentAlignment="Center" HorizontalAlignment="Left" Height="50" Margin="15,28,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="310" FontSize="40" FontWeight="Bold" MaxLength="15" MaxLines="15"/>
<Button Content="7" HorizontalAlignment="Left" Margin="15,105,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Siete" FontSize="24" FontWeight="Bold"/>
<Button Content="/" HorizontalAlignment="Left" Margin="210,300,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Dividir" FontSize="24" FontWeight="Bold"/>
<Button Content="*" HorizontalAlignment="Left" Margin="210,235,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Multiplicar" FontWeight="Bold" FontSize="24"/>
<Button Content="-" HorizontalAlignment="Left" Margin="210,170,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Restar" FontSize="24" FontWeight="Bold"/>
<Button Content="=" HorizontalAlignment="Left" Margin="145,300,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Igual" FontSize="24" FontWeight="Bold"/>
<Button Content="3" HorizontalAlignment="Left" Margin="145,235,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Tres" FontSize="24" FontWeight="Bold"/>
<Button Content="6" HorizontalAlignment="Left" Margin="145,170,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Seis" FontSize="24" FontWeight="Bold"/>
<Button Content="." HorizontalAlignment="Left" Margin="80,300,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Punto" FontSize="24" FontWeight="Bold"/>
<Button Content="2" HorizontalAlignment="Left" Margin="80,235,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Dos" FontWeight="Bold" FontSize="24"/>
<Button Content="5" HorizontalAlignment="Left" Margin="80,170,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Cinco" FontSize="24" FontWeight="Bold"/>
<Button Content="0" HorizontalAlignment="Left" Margin="15,301,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Cero" FontSize="24" FontWeight="Bold"/>
<Button Content="1" HorizontalAlignment="Left" Margin="15,235,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Uno" FontSize="24" FontWeight="Bold"/>
<Button Content="4" HorizontalAlignment="Left" Margin="15,170,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Cuatro" FontSize="24" FontWeight="Bold"/>
<Button Content="8" HorizontalAlignment="Left" Margin="80,105,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Ocho" FontSize="24" FontWeight="Bold"/>
<Button Content="9" HorizontalAlignment="Left" Margin="145,105,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Nueve" FontSize="24" FontWeight="Bold"/>
<Button Content="+" HorizontalAlignment="Left" Margin="210,105,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Sumar" FontSize="24" FontWeight="Bold"/>
<Button Content="C" HorizontalAlignment="Left" Margin="275,105,0,0" VerticalAlignment="Top" Width="50" Height="50" Click="Presiona_Clear" FontSize="24" FontWeight="Bold"/>
</Grid>
</Window>
==================================================================
//Codigo archivo: MainWindows.xaml.cs
=============================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CalculadoraWPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
double primera_Entrada;
double segunda_Entrada;
double resultado;
string operador;
public MainWindow()
{
InitializeComponent();
}
private void Presiona_Cero(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "0";
}
private void Presiona_Uno(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "1";
}
private void Presiona_Dos(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "2";
}
private void Presiona_Tres(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "3";
}
private void Presiona_Cuatro(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "4";
}
private void Presiona_Cinco(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "5";
}
private void Presiona_Seis(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "6";
}
private void Presiona_Siete(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "7";
}
private void Presiona_Ocho(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "8";
}
private void Presiona_Nueve(object sender, RoutedEventArgs e)
{
Textbox_Screen.Text = Textbox_Screen.Text + "9";
}
private void Presiona_Sumar(object sender, RoutedEventArgs e)
{
operador = "+";
primera_Entrada = double.Parse(Textbox_Screen.Text);
Textbox_Screen.Clear();
}
private void Presiona_Restar(object sender, RoutedEventArgs e)
{
operador = "-";
primera_Entrada = double.Parse(Textbox_Screen.Text);
Textbox_Screen.Clear();
}
private void Presiona_Multiplicar(object sender, RoutedEventArgs e)
{
operador = "*";
primera_Entrada = double.Parse(Textbox_Screen.Text);
Textbox_Screen.Clear();
}
private void Presiona_Dividir(object sender, RoutedEventArgs e)
{
operador = "/";
primera_Entrada = double.Parse(Textbox_Screen.Text);
Textbox_Screen.Clear();
}
private void Presiona_Punto(object sender, RoutedEventArgs e)
{
if (Textbox_Screen.Text.Contains("."))
{
}
else
{
Textbox_Screen.Text = Textbox_Screen.Text + ".";
}
}
private void Presiona_Igual(object sender, RoutedEventArgs e)
{
segunda_Entrada = double.Parse(Textbox_Screen.Text);
switch (operador)
{
case "+":
resultado = primera_Entrada + segunda_Entrada;
Textbox_Screen.Text = resultado.ToString();
break;
case "-":
resultado = primera_Entrada - segunda_Entrada;
Textbox_Screen.Text = resultado.ToString();
break;
case "*":
resultado = primera_Entrada * segunda_Entrada;
Textbox_Screen.Text = resultado.ToString();
break;
case "/":
resultado = primera_Entrada / segunda_Entrada;
Textbox_Screen.Text = resultado.ToString();
break;
}
}
private void Presiona_Clear(object sender, RoutedEventArgs e)
{
Textbox_Screen.Clear();
}
}
}
No hay comentarios.:
Publicar un comentario