首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

相干text控件的sellength和selstart

2013-01-01 
有关text控件的sellength和selstartPrivate Sub Form_Load()Text1.Text text1里面的字符被选中!Text1.

有关text控件的sellength和selstart
Private Sub Form_Load()
Text1.Text = "text1里面的字符被选中!"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub

Private Sub Command1_Click()
Text1.Text = "为什么text1里面的字符没被选中?"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
[解决办法]
Private Sub Form_Load()
    Show
    With Text1
        .Text = "text1里面的字符被选中!"
    
        .SelStart = 0
        .SelLength = Len(Text1.Text)
        .SetFocus
    End With
    
End Sub

[解决办法]
实际上是选中的。但由于点击按钮 Command1 使 Text1 失去焦点,你看不到反白显示。
试试用 Tab 键跳回 Text1,就看到选中了。
如果想按 Command1 后立即看到选中效果,要使 Text1 获得焦点。如下:

Private Sub Command1_Click()
Text1.Text = "为什么text1里面的字符没被选中?"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.SetFocus
End Sub

热点排行