Hi,everyone.
I would like to know how to turn on and off the cursor in the textbox control?
Thanks for your help.
Printable View
Hi,everyone.
I would like to know how to turn on and off the cursor in the textbox control?
Thanks for your help.
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
why do you want to turn on/off the cursor? what you would like to do?
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
Good point JA, I wrote the example before engaging my brain.
Hey guys,
Could you tell me what is the use of hiding and showing the cursor in text box?
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.
To restrict the user to enter something in text box we can use the locked property right.
but the caret is still displayed, so you need to hide it.
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.
Ok thanks. Now I understood everything.