TOP

Calculadora Básica - Visual Básic Windows Form - WPF




DISEÑO DEL FORMULARIO - WPF - XAML

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CALCULADORA BÁSICA" WindowStyle="ToolWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" FontWeight="Bold" ShowActivated="False" Height="313" Width="246">
    <Grid Height="267" Width="207">
        <Button Content="7" Height="30" HorizontalAlignment="Left" Margin="23,67,0,0" Name="Btn7" VerticalAlignment="Top" Width="35" />
        <Button Content="8" Height="30" HorizontalAlignment="Left" Margin="64,67,0,0" Name="Btn8" VerticalAlignment="Top" Width="35" />
        <Button Content="9" Height="30" HorizontalAlignment="Left" Margin="105,67,0,0" Name="Btn9" VerticalAlignment="Top" Width="35" />
        <Button Content="+" Height="30" HorizontalAlignment="Left" Margin="145,67,0,0" Name="BtnSuma" VerticalAlignment="Top" Width="35" />
        <Button Content="4" Height="30" HorizontalAlignment="Left" Margin="23,103,0,0" Name="Btn4" VerticalAlignment="Top" Width="35" />
        <Button Content="5" Height="30" HorizontalAlignment="Left" Margin="64,103,0,0" Name="Btn5" VerticalAlignment="Top" Width="35" />
        <Button Content="6" Height="30" HorizontalAlignment="Left" Margin="105,103,0,0" Name="Btn6" VerticalAlignment="Top" Width="35" />
        <Button Content="-" Height="30" HorizontalAlignment="Left" Margin="146,103,0,0" Name="BtnMenos" VerticalAlignment="Top" Width="35" />
        <Button Content="1" Height="30" HorizontalAlignment="Left" Margin="23,139,0,0" Name="Btn1" VerticalAlignment="Top" Width="35" />
        <Button Content="2" Height="30" HorizontalAlignment="Left" Margin="64,139,0,0" Name="Btn2" VerticalAlignment="Top" Width="35" />
        <Button Content="3" Height="30" HorizontalAlignment="Left" Margin="105,139,0,0" Name="Btn3" VerticalAlignment="Top" Width="35" />
        <Button Content="x" Height="30" HorizontalAlignment="Left" Margin="146,139,0,0" Name="BtnMulti" VerticalAlignment="Top" Width="35" />
        <Button Content="0" Height="30" HorizontalAlignment="Left" Margin="23,175,0,0" Name="Btn0" VerticalAlignment="Top" Width="35" />
        <Button Content="C" Height="30" HorizontalAlignment="Left" Margin="64,175,0,0" Name="BtnC" VerticalAlignment="Top" Width="35" />
        <Button Content="=" Height="30" HorizontalAlignment="Left" Margin="105,175,0,0" Name="BtnIgual" VerticalAlignment="Top" Width="35" />
        <Button Content="÷" Height="30" HorizontalAlignment="Left" Margin="146,0,0,62" Name="ButDiv" VerticalAlignment="Bottom" Width="35" />
        <TextBox Height="38" HorizontalAlignment="Left" Margin="25,21,0,0" Name="txtcaja" VerticalAlignment="Top" Width="155" Text="0" TextAlignment="Right" FontSize="20" FontWeight="Bold" IsEnabled="False" />
        <Label Content="Roberto Gonzales" Height="28" HorizontalAlignment="Left" Margin="25,213,0,0" Name="Label1" VerticalAlignment="Top" Background="{x:Null}" FontWeight="Bold" Width="155" FontSize="15">
            <Label.Foreground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#E6DF229E" Offset="1" />
                    <GradientStop Color="#FF2C3B35" Offset="0" />
                    <GradientStop Color="#FF181816" Offset="0.006" />
                </LinearGradientBrush>
            </Label.Foreground>
        </Label>
        <Label Content="Elcodigomaestro.Tk" Height="35" HorizontalAlignment="Left" Margin="22,232,0,0" Name="Label2" VerticalAlignment="Top" Width="158" FontSize="16">
            <Label.Foreground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF1438E2" Offset="0" />
                    <GradientStop Color="#FFB85ED9" Offset="1" />
                </LinearGradientBrush>
            </Label.Foreground>
        </Label>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0.512" />
                <GradientStop Color="#FF4BB2E2" Offset="1" />
                <GradientStop Color="#FF1A3F50" Offset="0.006" />
            </LinearGradientBrush>
        </Grid.Background>
    </Grid>
    
</Window>


CÓDIGO DEL FORMULARIO : MainWindow.xaml.vb

El código es igual que Visual Basic Windows Form


Class MainWindow

    Dim num As Double = 0
    Dim Operador As String

    Private Sub Btn7_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn7.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 7
    End Sub

    Private Sub Btn8_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn8.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 8
    End Sub

    Private Sub Btn9_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn9.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 9
    End Sub

    Private Sub Btn4_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn4.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 4
    End Sub

    Private Sub Btn5_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn5.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 5
    End Sub

    Private Sub Btn6_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn6.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 6
    End Sub

    Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn1.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 1
    End Sub

    Private Sub Btn2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn2.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 2
    End Sub

    Private Sub Btn3_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn3.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10) + 3
    End Sub

    Private Sub Btn0_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn0.Click
        txtcaja.Text = (CDbl(txtcaja.Text) * 10)
    End Sub

    Private Sub BtnSuma_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnSuma.Click
        num = CDbl(txtcaja.Text)
        Operador = "+"
        txtcaja.Text = 0
    End Sub

    Private Sub BtnMenos_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnMenos.Click
        num = CDbl(txtcaja.Text)
        Operador = "-"
        txtcaja.Text = 0
    End Sub

    Private Sub BtnMulti_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnMulti.Click
        num = CDbl(txtcaja.Text)
        Operador = "x"
        txtcaja.Text = 0
    End Sub

    Private Sub ButDiv_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButDiv.Click
        num = CDbl(txtcaja.Text)
        Operador = "/"
        txtcaja.Text = 0
    End Sub

    Private Sub BtnIgual_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnIgual.Click
        Select Case Operador
            Case "+" : txtcaja.Text = CDbl(num) + CDbl(txtcaja.Text)
            Case "-" : txtcaja.Text = CDbl(num) - CDbl(txtcaja.Text)
            Case "x" : txtcaja.Text = CDbl(num) * CDbl(txtcaja.Text)
            Case "/" : txtcaja.Text = CDbl(num) / CDbl(txtcaja.Text)
        End Select
    End Sub

    Private Sub BtnC_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnC.Click
        num = 0
        txtcaja.Text = 0
    End Sub

   End Class


1 comentarios:

  1. sería bueno que lo realizaran usando enlaces de datos, en WPF gracias.

Publicar un comentario

Danos tu opinión o déjanos tu ejercicio! - Algoritmos, pseudocódigo y lo pasamos a Visual Basic consola.