关于Text的一个问题
form1上有一TextBox1,当form1显示的时候就选中textbox1.text中的文本 问题点数:10、回复次数:7Top
1 楼rainstormmaster(暴风雨 v2.0)回复于 2003-09-02 01:29:26 得分 2
Option Explicit
Private Sub Form_Load()
Text1.Text = "1234567"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Me.Show
Text1.SetFocus
End Sub
Top
2 楼chanet(牧师)回复于 2003-09-02 01:51:26 得分 1
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Top
3 楼callzjy((草魚))回复于 2003-09-02 02:46:29 得分 1
Private Sub Form_Load()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Me.Show
Text1.SetFocus
End SubTop
4 楼ch21st(www.blanksoft.com)回复于 2003-09-02 08:26:50 得分 3
楼主的问题大家说的都很明白了,不过我在补充一点其他的方法,就是用api
这个例子适合多行文本,选择任意文本块
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const EM_GETSEL As Long = &HB0
Private Const EM_SETSEL As Long = &HB1
Private Const EM_GETLINECOUNT As Long = &HBA
Private Const EM_LINEINDEX As Long = &HBB
Private Const EM_LINELENGTH As Long = &HC1
Private Const EM_LINEFROMCHAR As Long = &HC9
Private Const EM_SCROLLCARET As Long = &HB7
Private Const WM_SETREDRAW As Long = &HB
Public Function GetBlockText(ctl As TextBox, _
passedLineStart As Long, _
passedLineEnd As Long) As String
Dim copyStart As Long
Dim copyEnd As Long
Dim currLine As Long
Dim lineCount As Long
Dim success As Long
Dim currCursorPos As Long
ctl.SetFocus
If Check1.Value = 1 Then
currCursorPos = ctl.SelStart
Call SendMessage(ctl.hwnd, WM_SETREDRAW, False, ByVal 0&)
DoEvents
End If
'--------------------------------
'get the number of lines in the textbox
lineCount = SendMessage(ctl.hwnd, EM_GETLINECOUNT, 0, ByVal 0&)
passedLineStart = passedLineStart - 1
'proceeding only if there are lines to work with
If lineCount > 0 Then
'if the startline greater than 0
If passedLineStart > 0 Then
'get the number of chrs up to the
'end of the desired start line
copyStart = SendMessage(ctl.hwnd, _
EM_LINEINDEX, _
passedLineStart, ByVal 0&)
Else: 'start at the beginning
'of the textbox
copyStart = 0
End If
'if the lastline greater than 0 and
'less then the number of lines in the
'control..
If passedLineEnd > 0 And _
passedLineEnd <= lineCount Then
'..get the number of chrs up to the
'end of the desired last line
copyEnd = SendMessage(ctl.hwnd, _
EM_LINEINDEX, _
passedLineEnd, ByVal 0&)
Else: 'copy the whole thing
copyEnd = Len(ctl)
End If
success = SendMessage(ctl.hwnd, _
EM_SETSEL, _
copyStart, _
ByVal copyEnd)
If success <> -1 Then
'return the selected text
GetBlockText = ctl.SelText
End If
End If
'-------------------------------
'optional: used to end transparent action
If Check1.Value = 1 Then
ctl.SelStart = currCursorPos
Call SendMessage(ctl.hwnd, WM_SETREDRAW, True, ByVal 0&)
Else
'scroll the selected item into view
Call SendMessage(ctl.hwnd, EM_SCROLLCARET, 0, ByVal 0)
End If
'--------------------------------
End FunctionTop
5 楼cuizm(射天狼 http://www.j2soft.cn/)回复于 2003-09-02 08:35:59 得分 1
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.TabIndex = 0Top
6 楼chao778899(220330)回复于 2003-09-02 08:59:17 得分 1
Option Explicit
Private Sub Form_Load()
Text1.Text = "1234567"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Me.Show
Text1.SetFocus
End Sub
Top
7 楼stonelang()回复于 2003-09-02 10:27:13 得分 1
if form1.show then text1.setfocusTop




