回答我自己的問題,與此
Private Sub capitalTB_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles capitalTB.Validating
Dim currency As Decimal
'Convert the current value to currency, with or without a currency symbol.
If Not Decimal.TryParse(Me.capitalTB.Text, _
Globalization.NumberStyles.Currency, _
Nothing, _
currency) Then
'Don't let the user leave the field if the value is invalid.
With Me.capitalTB
.HideSelection = False
.SelectAll()
MessageBox.Show("Please enter a valid capital amount.", _
"Invalid Capital", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
.HideSelection = True
End With
e.Cancel = True
End If
End Sub
Private Sub capitalTB_Validated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles capitalTB.Validated
'Display the value as local currency.
Me.capitalTB.Text = Decimal.Parse(Me.capitalTB.Text).ToString("c")
End Sub
由於解決了@Avijit貨幣屏蔽。
不要手動做。當您發佈貨幣值時使用ToString:'someTB.Text = someAmount.ToString(「C2」)'它將顯示當前文化的正確貨幣符號。除此之外,「它不工作」並不描述我們可以解決的問題 – Plutonix 2014-12-27 13:59:24
已更新問題 – Teddybugs 2014-12-27 14:00:12
您可以使用['貨幣掩碼 - 文本框]](http://www.codeproject.com/Articles/248989/A -Currency-Masked-TextBox-from-TextBox-Class)根據需要使用$符號。 – Avijit 2014-12-27 14:18:14