如何将负数放到文本框中,如下图所示? [英] How Can I Put The Negative Number To the Textbox like the picture below?

查看:97
本文介绍了如何将负数放到文本框中,如下图所示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://i58.tinypic.com/25fndc6.jpg [ ^ ]

如何将负数更改为文本框?如图下面





这里我的代码!!

 Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button1.Click 
Dim i As Double = txtpayment.Text
i - = txtname.Text
txtbalance.Text = + -i.ToString


结束子

解决方案

嗯,我建议从不开始试图从一个数字中减去一个名字 - 它通常效果不好......



我还建议使用int.TryParse将文本框值转换为数字 - 如果用户键入非数字值,则显示错误报告。

  Dim  char ge 作为 整数 
如果 整数 .TryParse(txtCharge.Text,charge)然后
' 报告错误
...
返回
结束 如果
Dim payment 作为 整数
如果 整数 .TryParse (txtPayment.Text,付款)然后
' 报告错误
...
返回
结束 如果
Dim balance < span class =code-keyword> As Integer = charge - payment
txtBalance.Text = balance.ToString()


http://i58.tinypic.com/25fndc6.jpg[^]
how can i put the negative number to change textbox?like the picture below


here my code!!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim i As Double = txtpayment.Text
       i -= txtname.Text
       txtbalance.Text = +-i.ToString


   End Sub

解决方案

Well, I would suggest starting by not trying to subtract a name from a number - it generally doesn't work too well...

I would also suggest using int.TryParse to convert the textbox values to numbers - with error reporting if the user types a non-numeric value.

Dim charge As Integer
If Not Integer.TryParse(txtCharge.Text, charge) Then
    ' Report error
    ...
    Return
End If
Dim payment As Integer
If Not Integer.TryParse(txtPayment.Text, payment) Then
    ' Report error
    ...
    Return
End If
Dim balance As Integer = charge - payment
txtBalance.Text = balance.ToString()


这篇关于如何将负数放到文本框中,如下图所示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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