Bom amigos
depois de algum tempo sem posta nem um conteúdo novo no blog resolvi
desenvolver essa calculadora Dark Pink em C# completa e funcional.
Confesso
que pensei em desistir, às coisas estavam ficando um pouco complicada na minha
vida, uma decepção atrás da outra. Hoje então meu mundo desabou, mas vou
continuar não vai ser alguns obstáculos e decepções que vai conseguir me parar,
você deve esta pensando o que tenho com isso? Simples se você esta desanimado e
pensando em desistir, aconselho a não fazer isso, vamos seguir em frente ai, “No
fim tudo dá certo, se não deu certo é porque ainda não chegou o fim” – Fernando
Sabino.
Então vamos ao
que interessa, esta calculadora é voltada para o público feminino do blog que
tenho certeza que é quase zero, se não for zero, mas vamos lá, embaixo esta o código para o
Design da calculadora e o que faz efetuar os cálculos, tem alguns bugs, mas não
deixa de ser interessante.
Imagem da calculadora
Código do design
<Window x:Class="Calculadora.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="389" Width="283" Background="White" WindowStyle="ThreeDBorderWindow">
<Grid Width="264" Height="351">
<Grid.Background>
<ImageBrush
ImageSource="/WpfApplication1;component/Images/Pink_by_DaniieeLaaa.jpggirl_.jpg"
/>
</Grid.Background>
<Button Content="7" Height="28" HorizontalAlignment="Left" Margin="12,130,0,0" Name="sete"
VerticalAlignment="Top" Width="37"
Click="sete_Click" />
<TextBox Height="41" HorizontalAlignment="Right" Margin="0,49,43,0" Name="display" VerticalAlignment="Top" Width="209" FontFamily="Arial" FontSize="28"
HorizontalContentAlignment="Right" Background="#3EFF0000" />
<Button Content="8" Height="28" HorizontalAlignment="Left" Margin="55,130,0,0" Name="oito"
VerticalAlignment="Top" Width="37"
Click="oito_Click" />
<Button Content="9" Height="28" HorizontalAlignment="Left" Margin="98,130,0,0" Name="nove"
VerticalAlignment="Top" Width="37"
Click="nove_Click" />
<Button Content="4" Height="28" HorizontalAlignment="Left" Margin="12,164,0,0" Name="quatro"
VerticalAlignment="Top" Width="37"
Click="quatro_Click" />
<Button Content="5" Height="28" HorizontalAlignment="Left" Margin="55,164,0,0" Name="cinco"
VerticalAlignment="Top" Width="37"
Click="cinco_Click" />
<Button Content="6" Height="28" HorizontalAlignment="Left" Margin="98,164,0,0" Name="seis"
VerticalAlignment="Top" Width="37"
Click="seis_Click" />
<Button Content="1" Height="28" HorizontalAlignment="Left" Margin="12,198,0,0" Name="um"
VerticalAlignment="Top" Width="37"
Click="um_Click" />
<Button Content="2" Height="28" HorizontalAlignment="Left" Margin="55,0,0,125" Name="dois"
VerticalAlignment="Bottom" Width="37"
Click="dois_Click" />
<Button Content="3" Height="28" HorizontalAlignment="Left" Margin="98,198,0,0" Name="tres"
VerticalAlignment="Top" Width="37"
Click="tres_Click" />
<Button Content="0" Height="28" HorizontalAlignment="Left" Margin="12,232,0,0" Name="zero"
VerticalAlignment="Top" Width="80"
Click="zero_Click" />
<Button Content="," HorizontalAlignment="Left" Margin="98,232,0,91" Name="virgula" Width="37" FontSize="18" Click="virgula_Click" />
<Button Content="+" Height="28" HorizontalAlignment="Left" Margin="141,232,0,0" Name="soma"
VerticalAlignment="Top" Width="37"
Click="soma_Click" />
<Button Content="-" Height="28" HorizontalAlignment="Left" Margin="141,198,0,0" Name="subtracao" VerticalAlignment="Top" Width="37"
Click="subtracao_Click" />
<Button Content="*" Height="28" HorizontalAlignment="Left" Margin="141,0,0,159" Name="multiplicacao" VerticalAlignment="Bottom" Width="37"
Click="multiplicacao_Click" />
<Button Content="/" Height="28" HorizontalAlignment="Left" Margin="141,130,0,0" Name="divisao" VerticalAlignment="Top" Width="37"
Click="divisao_Click" />
<Button Content="=" Height="60" HorizontalAlignment="Left" Margin="184,200,0,0" Name="igual"
VerticalAlignment="Top" Width="37"
Click="igual_Click" />
<Button Content="1/x" Height="28" HorizontalAlignment="Left" Margin="184,0,0,159" Name="inverso" VerticalAlignment="Bottom" Width="37" Click="inverso_Click" />
<Button Content="%" Height="28" HorizontalAlignment="Left" Margin="184,130,0,0" Name="percente" VerticalAlignment="Top" Width="37" />
<Button Content="<--" Height="28" HorizontalAlignment="Left" Margin="12,96,0,0" Name="voltar" VerticalAlignment="Top" Width="37" Click="voltar_Click" />
<Button Content="CE" Height="28" HorizontalAlignment="Left" Margin="55,96,0,0" Name="button1" VerticalAlignment="Top" Width="37" Click="button1_Click" />
<Button Content="C" Height="28" HorizontalAlignment="Left" Margin="98,96,0,0" Name="button2" VerticalAlignment="Top" Width="37"
Click="button2_Click" />
<Button Height="28" HorizontalAlignment="Right" Margin="0,96,43,0" Name="raiz" VerticalAlignment="Top" Width="37" Content="√" Click="raiz_Click"
/>
<Button Height="28" HorizontalAlignment="Left" Margin="141,96,0,0" Name="maisoumenos" VerticalAlignment="Top" Width="37" Content="±" Click="maisoumenos_Click"
/>
<Rectangle Height="30" HorizontalAlignment="Left" Name="rectangle1" Stroke="Black" VerticalAlignment="Top" Width="268" Fill="#52000000" Margin="-4,-1,0,0" />
<Rectangle Height="36" HorizontalAlignment="Left" Margin="0,315,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="265" Fill="#7C000000" />
<Label Content="Dionatan Alves Vieira"
Height="28"
HorizontalAlignment="Left" Margin="12,323,0,0" Name="label1"
VerticalAlignment="Top" Width="211"
Foreground="White" />
<Label Content="Calculadora C#" Height="28" HorizontalAlignment="Left" Margin="80,0,0,0" Name="label2" VerticalAlignment="Top" Width="98" Foreground="White" />
</Grid>
</Window>
Código Para
Efetuar os Cálculos
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
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
Calculadora
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
double acumula = 0;
string operacao = "";
public
MainWindow()
{
InitializeComponent();
}
private
void sete_Click(object
sender, RoutedEventArgs e)
{
display.Text += "7";
}
private
void zero_Click(object
sender, RoutedEventArgs e)
{
display.Text += "0";
}
private void
um_Click(object sender, RoutedEventArgs e)
{
display.Text += "1";
}
private
void dois_Click(object
sender, RoutedEventArgs e)
{
display.Text += "2";
}
private
void tres_Click(object
sender, RoutedEventArgs e)
{
display.Text += "3";
}
private
void quatro_Click(object
sender, RoutedEventArgs e)
{
display.Text += "4";
}
private void
cinco_Click(object sender, RoutedEventArgs e)
{
display.Text += "5";
}
private
void seis_Click(object
sender, RoutedEventArgs e)
{
display.Text += "6";
}
private
void oito_Click(object
sender, RoutedEventArgs e)
{
display.Text += "8";
}
private
void nove_Click(object
sender, RoutedEventArgs e)
{
display.Text += "9";
}
private
void soma_Click(object
sender, RoutedEventArgs e)
{
if (operacao == "*"
|| operacao=="-" || operacao == "/")
{
operacao = "+";
}
else
{
acumula += double.Parse(display.Text);
display.Text = "";
operacao = "+";
}
}
private
void igual_Click(object
sender, RoutedEventArgs e)
{
if
(operacao == "+")
{
acumula += double.Parse(display.Text);
display.Text =
acumula.ToString();
}
else
if (operacao == "-")
{
acumula -= double.Parse(display.Text);
display.Text = acumula.ToString();
}
else
if (operacao=="*"){
acumula *= double.Parse(display.Text);
display.Text =
acumula.ToString();
}
else
if (operacao == "/")
{
if
(double.Parse(display.Text) != 0)
{
acumula /= double.Parse(display.Text);
display.Text =
acumula.ToString();
}
else
{
display.Text = "Dividindo por zero";
}
}
}
private
void virgula_Click(object
sender, RoutedEventArgs e)
{
display.Text += ",";
}
private
void subtracao_Click(object
sender, RoutedEventArgs e)
{
if (operacao == "*"
|| operacao == "+" || operacao == "/")
{
operacao = "-";
} else {
acumula = double.Parse(display.Text);
display.Text = "";
operacao = "-";
}
}
private
void multiplicacao_Click(object sender, RoutedEventArgs
e)
{
if
(operacao == "-" || operacao == "+" || operacao == "/")
{
operacao = "*";
}
else
{
acumula = double.Parse(display.Text);
display.Text = "";
operacao = "*";
}
}
private
void divisao_Click(object
sender, RoutedEventArgs e)
{
if
(operacao == "*" || operacao == "+" || operacao == "-")
{
operacao = "/";
}
else
{
acumula = double.Parse(display.Text);
display.Text = "";
operacao = "/";}
}
private
void voltar_Click(object
sender, RoutedEventArgs e)
{
int
x = display.Text.Length-1;
if
(x >= 0)
{
display.Text =
display.Text.Substring(0, x);
}
}
private
void inverso_Click(object
sender, RoutedEventArgs e)
{
try
{
double
d = double.Parse(display.Text);
if (d == 0)
{
display.Text = "Dividindo por
zero!!!";
}
else
{
d = 1 / d;
display.Text =
d.ToString();
}
}
catch
(Exception Ex) {
for
(int i = 0; i < 100000; i++)
{
display.Text = "Para com isso
pisicopata. ";
//
em espera.
}
display.Text = "";
}
}
private
void raiz_Click(object
sender, RoutedEventArgs e)
{
double
x = double.Parse(display.Text);
if (x < 0)
{
display.Text = "Este valor não é
valido.";
}
else
{
x = Math.Sqrt(x);
display.Text = x.ToString();
}
}
private
void button2_Click(object
sender, RoutedEventArgs e)
{
acumula = 0;
display.Text = "";
}
private
void button1_Click(object
sender, RoutedEventArgs e)
{
display.Text = "";
operacao = "";
}
private
void maisoumenos_Click(object
sender, RoutedEventArgs e)
{
double
x = double.Parse(display.Text)*(-1);
display.Text = x.ToString();
}
}
}