|
-
May 14th, 2006, 06:14 AM
#1
Thread Starter
Hyperactive Member
How to turn on and off the cursor in the textbox?
Hi,everyone.
I would like to know how to turn on and off the cursor in the textbox control?
Thanks for your help.
-
May 14th, 2006, 06:18 AM
#2
Re: How to turn on and off the cursor in the textbox?
VB Code:
Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function HideCaret Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
HideCaret Text1.hwnd
End Sub
Private Sub Command2_Click()
ShowCaret Text1.hwnd
End Sub
-
May 14th, 2006, 07:10 AM
#3
Re: How to turn on and off the cursor in the textbox?
why do you want to turn on/off the cursor? what you would like to do?
-
May 14th, 2006, 07:10 AM
#4
Re: How to turn on and off the cursor in the textbox?
Even though Bushmobile showed the correct code it is placed in the wrong place. You can't really place the HideCaret call in the Click event of a command button (well you can but it wont work as expected). The reason is that only one control can have a text caret at one particular time, and when you click a button the textbox has lost focus and the caret has already been destroyed. It will however be recreated when the textbox regains focus again, so you should call HideCaret in the GotFocus event of the textbox instead.
VB Code:
Private Sub Text1_GotFocus()
HideCaret Text1.hwnd
End Sub
-
May 14th, 2006, 07:15 AM
#5
Re: How to turn on and off the cursor in the textbox?
Good point JA, I wrote the example before engaging my brain.
-
May 14th, 2006, 07:36 AM
#6
Re: How to turn on and off the cursor in the textbox?
Hey guys,
Could you tell me what is the use of hiding and showing the cursor in text box?
-
May 14th, 2006, 07:41 AM
#7
Re: How to turn on and off the cursor in the textbox?
well... you might want to just show text in the textbox, rather than allow the user to enter text, i.e. it behaves like a label, but you have all the extra functionality and ability to modify it because it has an hWnd.
-
May 14th, 2006, 07:44 AM
#8
Re: How to turn on and off the cursor in the textbox?
To restrict the user to enter something in text box we can use the locked property right.
-
May 14th, 2006, 07:45 AM
#9
Re: How to turn on and off the cursor in the textbox?
but the caret is still displayed, so you need to hide it.
-
May 14th, 2006, 07:54 AM
#10
Re: How to turn on and off the cursor in the textbox?
Hiding the caret doesn't restrict the user from entering text by itself so the Locked property must also be set. But as Bushmobile said there are times when you might want the textbox to act as a scrollable label but you don't want the annoying flashing caret to appear. The caret is pretty useless if you don't allow the user to enter text.
-
May 14th, 2006, 07:59 AM
#11
Re: How to turn on and off the cursor in the textbox?
Ok thanks. Now I understood everything.
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
|