|
-
Nov 6th, 2005, 10:35 AM
#1
-
Nov 6th, 2005, 10:45 AM
#2
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
Without seeing your code I can't say why this doesn't work. If I highlight text in a TextBox the cursor blinks at the begining of the highlighted text.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Nov 6th, 2005, 10:49 AM
#3
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
How do we make it blink at start of selection?
VB Code:
Private Sub Command1_Click()
Text1.Text = "Hello World"
Text1.SelStart = 4
Text1.SelLength = Len(Text1)
Text1.SetFocus
End Sub
-
Nov 6th, 2005, 11:43 AM
#4
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
The code in above post will select the required text but the cursor will blink at the end of selected text. I need to make it blink at the beginning of selected text.
When you select text using mouse from right to left (end to beginning), you will get the effect I require.
Pradeep
-
Nov 6th, 2005, 01:05 PM
#5
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
Here
VB Code:
Option Explicit
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_SETSEL = &HB1
Private Sub Command1_Click()
Dim StartPos As Long
Dim EndPos As Long
Text1.Text = "Hello World"
StartPos = InStr(Text1.Text, "World") - 1
EndPos = Len(Text1.Text)
SendMessage Text1.hwnd, EM_SETSEL, EndPos, ByVal StartPos
Text1.SetFocus
End Sub
-
Nov 6th, 2005, 01:33 PM
#6
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
 Originally Posted by moeur
Here
VB Code:
Option Explicit
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_SETSEL = &HB1
Private Sub Command1_Click()
Dim StartPos As Long
Dim EndPos As Long
Text1.Text = "Hello World"
StartPos = InStr(Text1.Text, "World") - 1
EndPos = Len(Text1.Text)
SendMessage Text1.hwnd, EM_SETSEL, EndPos, ByVal StartPos
Text1.SetFocus
End Sub
This is also doing the same thing. 
Pradeep
-
Nov 6th, 2005, 01:47 PM
#7
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
Make your textbox multiline and it will do what you want
-
Nov 10th, 2005, 02:33 PM
#8
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
Yes it works perfectly 
Is it somehow possible for a non-multiline textbox? I don't want the user to have multiline text in the box.
Pradeep
-
Nov 10th, 2005, 06:06 PM
#9
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
Just add this code to prevent user from entering multilines
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCr) Then KeyAscii = 0
End Sub
-
Nov 11th, 2005, 08:58 AM
#10
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
 Originally Posted by moeur
Just add this code to prevent user from entering multilines
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCr) Then KeyAscii = 0
End Sub
The Enter mark is not a big problem, the problem is that if the sentence goes long, it will wrap to next line which is not visible. With non-multilne textboxes, it remains in the same line and the workaround is quite clumsy.
Pradeep
-
Nov 12th, 2005, 03:43 AM
#11
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
 Originally Posted by Pradeep1210
The Enter mark is not a big problem, the problem is that if the sentence goes long, it will wrap to next line which is not visible. With non-multilne textboxes, it remains in the same line and the workaround is quite clumsy.
Pradeep
well, if multiline is a problem, in that case you can use the scroll bars of the text box to avoid that problem. i tried using the above code and the scroll bar thing:
VB Code:
Option Explicit
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
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 SB_HORZ = 0
Private Const EM_SETSEL = &HB1
Private Sub Command1_Click()
Dim StartPos As Long
Dim EndPos As Long
Text1.Text = "Helloooooooooooooo Worlddddddddddddddddddddddddd"
StartPos = InStr(Text1.Text, "World") - 1
EndPos = Len(Text1.Text)
SendMessage Text1.hwnd, EM_SETSEL, EndPos, ByVal StartPos
Text1.SetFocus
End Sub
Private Sub Form_Load()
ShowScrollBar Text1.hwnd, SB_HORZ, 0
End Sub
Private Sub Text1_Change()
If Me.TextWidth(Text1.Text) > Text1.Width Then
ShowScrollBar Text1.hwnd, SB_HORZ, 1&
Else
ShowScrollBar Text1.hwnd, SB_HORZ, 0&
End If
End Sub
hope this helps you.
-
Nov 12th, 2005, 03:45 AM
#12
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
oh i forgot, make the textbox multiline and in scroll bar properties, make it horizontal.
-
Nov 12th, 2005, 08:44 AM
#13
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
Ah yes Gupta,
Adding a scroll bar turns off word wrap and you can always hide the scroll bar if you don't want it.
-
Nov 12th, 2005, 10:36 AM
#14
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
The scroll bars make the situation worse. Actually I want to simulate an autocomplete combobox. This I am doing by adding a TextBox and Listbox. So as soon as the scrollbars appear or the textwraps, it seems awckward.
At present all my code works perfect except the cursor blinking position when it is not multiline. So I need to make it better than that.
Pradeep
-
Nov 12th, 2005, 11:49 AM
#15
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
What is wrong with this?
VB Code:
Option Explicit
'Set TExt1.Multiline = true
'Set TExt.ScrollBArs = 1- Horizontal
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
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 SB_HORZ = 0
Private Const EM_SETSEL = &HB1
Private Sub Command1_Click()
Dim StartPos As Long
Dim EndPos As Long
StartPos = InStr(Text1.Text, "World") - 1
EndPos = Len(Text1.Text)
SendMessage Text1.hwnd, EM_SETSEL, EndPos, ByVal StartPos
Text1.SetFocus
End Sub
Private Sub Form_Load()
ShowScrollBar Text1.hwnd, SB_HORZ, 0
Text1.Text = "Helloooooooooooooo Worlddddddddddddddddddddddddd"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCr) Then KeyAscii = 0
End Sub
-
Nov 12th, 2005, 11:57 AM
#16
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
It wraps to the second line while my textbox height is equivalent to the height of a combobox (i.e. just one line).
OR it will show a horizontal scrollbar which doesn't appear natural.
Pradeep
-
Nov 12th, 2005, 12:05 PM
#17
Re: Selecting Text in a Standard Textbox - Cursor blinking problem
Yes! It's working 
Thanks,
Pradeep
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|