1.当值为空时,显示¥0.00并不难呀,初始值设为这个,然后在textbox的textchanged事件中写
if textbox1.text="" then
textbox1.text="¥0.00"
end if
但是也还是需要规划一下。判断一下text中只能有一个"."如果有一个,则不能再输入"."等细节问题。
2.你的Userctl,不能取text值,也不能赋值的问题这样来试试:
private tempText as string
Property SGText( ) As string
Get
Return tempText
End Get
Set(ByVal Value As string)
tempText = Value
End Set
End Property
然后在textbox的textchanged事件中:
me.SGtext=textbox1.text
然后在外部你也可以用这个属性来读值,但不要赋值。
我只是一时想到就写了,你如果只是想在外部读到textbox1的text值,最简单的方法就是把textbox1的修饰符变为public即可,默认的是friend。
但规范的方法应该是通过属性来做。
做个抛砖引玉吧,只处理了数值框与¥ 的处理,没有处理0.00的格式:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not (IsNumeric(e.KeyChar) Or e.KeyChar = ChrW(8) Or e.KeyChar = ChrW(46)) Then
e.Handled = True
Else
If IsNumeric(e.KeyChar) Then
If Microsoft.VisualBasic.Left(TextBox1.Text, 1) <> "¥" Then
TextBox1.Text = "¥" + TextBox1.Text + e.KeyChar
e.Handled = True
TextBox1.SelectionStart = TextBox1.Text.Length
End If
End If
End If
End Sub