none
Calculadora com teclado numérico RRS feed

  • Pergunta

  •  Estou tentando fazer uma calculadora mas estou com problemas para  inserir os números no textbox, ah mas porém tenho 03 textbox e fiz um teclado númerico e queria que ao selecionar uma textbox conseguisse inserir os números nesse textbox, se selecionasse outra textbox inserisse os números nessa outra textbox que está selecionada.

    Tentei fazer assim mas não deu certo.

    Public Class Form1
        Inherits System.Windows.Forms.Form
        Dim Vn As Double
        Dim Ve As Double
        Dim I As Double
        Dim R As Double
        Dim Rv As Double
        Dim Rt As Double
        Dim Z As Double
        Dim Zv As Double
        Dim Zt As Double
        Dim Xc As Double
        Dim Xt As Double
        Dim C As Double
        Dim Cap As Double
        Dim Vcap As Double
        Dim Valor As Integer
       
        Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += ","
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += ","
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += ","
            End If
    
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "1"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "1"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "1"
            End If
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "2"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "2"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "2"
            End If
    
        End Sub
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "3"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "3"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "3"
            End If
    
        End Sub
    
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "4"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "4"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "4"
            End If
    
        End Sub
    
        Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "5"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "5"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "5"
            End If
        End Sub
    
        Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "6"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "6"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "6"
            End If
    
        End Sub
    
        Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "7"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "7"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "7"
            End If
        End Sub
    
        Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "8"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "8"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "8"
            End If
        End Sub
    
        Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "9"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "9"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "9"
            End If
    
        End Sub
    
        Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "0"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "0"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "0"
            End If
    
        End Sub
    
        Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
    
            If TextBox1.Text < " " Then
                TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1 + 1)
            Else
                TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1)
            End If
    
        End Sub
    
        Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
    
            If TextBox1.Text = "" Then
                MessageBox.Show("Por favor preencher campo V IN", "Calc", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf TextBox2.Text = "" Then
                MessageBox.Show("Por favor preencher campo Corrente", "Calc", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf TextBox3.Text = "" Then
                MessageBox.Show("Por favor preencher campo V OUT", "Calc", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
    
            Else
               ' aqui ele faz a equação e me da o resultado em
    um label
    
            End If
    
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'Label4 = New Label()
            PictureBox1.Controls.Add(Label4)
    
            Label4.Parent = PictureBox1
    
            Label4.Location = New Point(55, 25)
    
            Label4.Text = FontStyle.Bold
    
            Label4.Text = FontStyle.Underline
    
            Label4.Text = FontStyle.Italic
    
            Label4.BackColor = Color.Transparent
    
            Label4.Text = ""
    
        End Sub
    
        Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
    
            TextBox1.Text = ""
    
            TextBox2.Text = ""
    
            TextBox3.Text = ""
    
            PictureBox1.Image = Nothing
    
            Label4.Text = ""
    
        End Sub
    
        Private Sub SairToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles SairToolStripMenuItem1.Click
    
            Dim result As MsgBoxResult
            result = MessageBox.Show("Deseja realmente sair", "Sair", _
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
            If result = MsgBoxResult.Ok Then
                Me.Close()
            End If
        End Sub
    
        Private Sub SobreToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SobreToolStripMenuItem.Click
            Sobre.Show()
    
        End Sub
    
        Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
            If (Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar))) Then
                e.Handled = True
            End If
            If e.KeyChar = Convert.ToChar(13) Then
                e.Handled = True
                SendKeys.Send("{TAB}")
            End If
    
        End Sub
        Private Sub TextBox3_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox3.KeyPress
            If (Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar))) Then
                e.Handled = True
            End If
            If e.KeyChar = Convert.ToChar(13) Then
                e.Handled = True
                Button13.PerformClick()
            End If
        End Sub
    
        Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
            If Not Char.IsNumber(e.KeyChar) And Not e.KeyChar = vbBack And Not e.KeyChar = "," Then
                e.Handled = True
            End If
            If e.KeyChar = Convert.ToChar(13) Then
                e.Handled = True
                SendKeys.Send("{TAB}")
            End If
        End Sub
    End Class




    • Tipo Alterado tiosaw sábado, 14 de novembro de 2015 00:58
    • Editado tiosaw sábado, 14 de novembro de 2015 01:11
    sexta-feira, 13 de novembro de 2015 01:17

Respostas

  •  Estou tentando fazer uma calculadora mas estou com problemas para  inserir os números no textbox, ah mas porém tenho 03 textbox e fiz um teclado númerico e queria que ao selecionar uma textbox conseguisse inserir os números nesse textbox, se selecionasse outra textbox inserisse os números nessa outra textbox que está selecionada.

    Tentei fazer assim mas não deu certo.

    Public Class Form1
        Inherits System.Windows.Forms.Form
        Dim Vn As Double
        Dim Ve As Double
        Dim I As Double
        Dim R As Double
        Dim Rv As Double
        Dim Rt As Double
        Dim Z As Double
        Dim Zv As Double
        Dim Zt As Double
        Dim Xc As Double
        Dim Xt As Double
        Dim C As Double
        Dim Cap As Double
        Dim Vcap As Double
        Dim Valor As Integer
       
        Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += ","
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += ","
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += ","
            End If
    
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "1"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "1"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "1"
            End If
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "2"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "2"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "2"
            End If
    
        End Sub
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "3"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "3"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "3"
            End If
    
        End Sub
    
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "4"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "4"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "4"
            End If
    
        End Sub
    
        Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "5"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "5"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "5"
            End If
        End Sub
    
        Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "6"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "6"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "6"
            End If
    
        End Sub
    
        Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "7"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "7"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "7"
            End If
        End Sub
    
        Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "8"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "8"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "8"
            End If
        End Sub
    
        Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "9"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "9"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "9"
            End If
    
        End Sub
    
        Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
            If TextBox1.TextLength = 0 Then
                TextBox1.Text += "0"
            ElseIf TextBox2.TextLength = 0 Then
                TextBox2.Text += "0"
            ElseIf TextBox3.TextLength = 0 Then
                TextBox3.Text += "0"
            End If
    
        End Sub
    
        Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
    
            If TextBox1.Text < " " Then
                TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1 + 1)
            Else
                TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1)
            End If
    
        End Sub
    
        Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
    
            If TextBox1.Text = "" Then
                MessageBox.Show("Por favor preencher campo V IN", "Calc", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf TextBox2.Text = "" Then
                MessageBox.Show("Por favor preencher campo Corrente", "Calc", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf TextBox3.Text = "" Then
                MessageBox.Show("Por favor preencher campo V OUT", "Calc", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
    
            Else
               ' aqui ele faz a equação e me da o resultado em
    um label
    
            End If
    
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'Label4 = New Label()
            PictureBox1.Controls.Add(Label4)
    
            Label4.Parent = PictureBox1
    
            Label4.Location = New Point(55, 25)
    
            Label4.Text = FontStyle.Bold
    
            Label4.Text = FontStyle.Underline
    
            Label4.Text = FontStyle.Italic
    
            Label4.BackColor = Color.Transparent
    
            Label4.Text = ""
    
        End Sub
    
        Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
    
            TextBox1.Text = ""
    
            TextBox2.Text = ""
    
            TextBox3.Text = ""
    
            PictureBox1.Image = Nothing
    
            Label4.Text = ""
    
        End Sub
    
        Private Sub SairToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles SairToolStripMenuItem1.Click
    
            Dim result As MsgBoxResult
            result = MessageBox.Show("Deseja realmente sair", "Sair", _
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
            If result = MsgBoxResult.Ok Then
                Me.Close()
            End If
        End Sub
    
        Private Sub SobreToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SobreToolStripMenuItem.Click
            Sobre.Show()
    
        End Sub
    
        Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
            If (Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar))) Then
                e.Handled = True
            End If
            If e.KeyChar = Convert.ToChar(13) Then
                e.Handled = True
                SendKeys.Send("{TAB}")
            End If
    
        End Sub
        Private Sub TextBox3_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox3.KeyPress
            If (Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar))) Then
                e.Handled = True
            End If
            If e.KeyChar = Convert.ToChar(13) Then
                e.Handled = True
                Button13.PerformClick()
            End If
        End Sub
    
        Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
            If Not Char.IsNumber(e.KeyChar) And Not e.KeyChar = vbBack And Not e.KeyChar = "," Then
                e.Handled = True
            End If
            If e.KeyChar = Convert.ToChar(13) Then
                e.Handled = True
                SendKeys.Send("{TAB}")
            End If
        End Sub
    End Class




    Consegui fazer funcionar o codigo....
    • Marcado como Resposta tiosaw sábado, 14 de novembro de 2015 20:24
    sábado, 14 de novembro de 2015 20:23