如何在没有单击按钮的情况下在文本框中显示和的值 [英] How to show the value of sum in Textbox without click Button

查看:65
本文介绍了如何在没有单击按钮的情况下在文本框中显示和的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想再问一遍。

Hi guys, i would like to ask more again.

我有两个Textbox和一个Combobox。文本框名称是txStay和txPay,Combobox的名称是txChoice

I have two Textbox and one Combobox. Textbox name's are txStay and txPay, name's of Combobox is txChoice

在Combobox内部有很多案例当我点击其中一个时,它会显示如下值:

Inside Combobox there's a lot of case that when I click one of them, it will show the value like this :

        Select Case cbChoice.SelectedItem
            Case "VIP"
                txPay.Text = "750,000"
            Case "Kelas I"
                txPay.Text = "500,000"
            Case "Kelas II"
                txPay.Text = "300,000"
            Case "Kelas III"
                txPay.Text = "150,000"
        End Select

然后当我将文本框'txStay'的值添加为Integer时,我想显示"<"的值txStay * txChoice"在'txPay'里面

Then when I add value of textbox 'txStay' as Integer, I want to show the value of "txStay * txChoice" inside 'txPay'

txChoice和txPay读为Double,所以我可以格式化为Double

That txChoice and txPay read as Double so I can format as Double

请给我任何结果?我很欣赏......

Any result, please? I'm so appreciate that...

谢谢

问候,

Aga

推荐答案

您好

非常混乱。

您正在进行一些不正确的编码,您可以根据自身和另一个文本框值设置文本框文本。

You are heading for a bad bit of coding where you are setting a textbox text with a value based on itself and another textbox value.

这就是你想要的,但前面有麻烦。

Here is what you say you want, but trouble ahead.

' Form1 with txChoice, txPay and txStay
Option Strict On
Option Explicit On
Public Class Form1
  Dim temp As Double = 0D
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    With txChoice
      .Items.Add("VIP")
      .Items.Add("Kelas I")
      .Items.Add("Kelas II")
      .Items.Add("Kelas III")
    End With
  End Sub
  Private Sub txChoice_SelectedIndexChanged(sender As Object, e As EventArgs) Handles txChoice.SelectedIndexChanged
    Dim cb As ComboBox = DirectCast(sender, ComboBox)
    Select Case cb.SelectedItem.ToString
      Case "VIP"
        txPay.Text = "750,000"
      Case "Kelas I"
        txPay.Text = "500,000"
      Case "Kelas II"
        txPay.Text = "300,000"
      Case "Kelas III"
        txPay.Text = "150,000"
    End Select
  End Sub
  Function Getdouble(s As String) As Double
    Dim v As Double = 0D
    If Double.TryParse(s, v) Then Return v
    Return 0D
  End Function
  Private Sub txStay_TextChanged(sender As Object, e As EventArgs) Handles txStay.Validated
    ' first, store the value before overwriting it.
    temp = Getdouble(txPay.Text)

    ' now calculate and overwrite.
    txPay.Text = (temp * Getdouble(txStay.Text)).ToString
  End Sub
End Class


这篇关于如何在没有单击按钮的情况下在文本框中显示和的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆