|
Text控件接受用户的输入的字符串数据。
[属性:]
·Text 表示用户输入的内容。
[例:]
Label1.Caption = Text1.Text
将Text1控件接收用户输入的数据通过Label1控件显示出来。
·SelStart 表示用户选中一段文字的起始位置。第一个字符位置为0。
·SelLength 表示用户选中文字的长度。
·SelText 表示用户选中文字的内容。
[例:]
0123456789
这时:SelStart=5,SelLength=4,SelText="5678"
·MultiLine 表示是否是多行输入。
=True 是多行输入。
=False 不是多行输入(缺省) 。
·ScrollBars 多行情况下是否需要滚动条。
=0 没有。
=1 有水平。
=2 有垂直。
=3 水平、垂直都有。
·Password 表示口令字符。Text属性返回用户输入数据,屏幕上显示该字符。
[方法:]
·SetFocus 使当前控件获得输入交点。
[事件:]
·KeyPress 当在控件上按下按键时发生。
Private Sub Text1_KeyPress(KeyAscii As Integer)
End Sub
·KeyAscii 表示用户按键的ASCII码,如果在事件中将它改为0,则认为没有按键。
[例:]
编写只允许输入数字的Text控件。
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If
End Sub
·Change 当控件内容改变时发生。
·LostFoucus 当控件失去输入交点时发生。
·GotFoucus 当控件获得输入交点时发生。
通常我们在Text控件获得输入交点时全选它的内容,方便用户直接修改数据。代码如下:
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
|