How can suppress (wipe off) the cursor of a field

  • Thread starter Thread starter giannis
  • Start date Start date
G

giannis

How can suppress (wipe off) the cursor of a field
in a form without set the propery "Enabled" to No ?
(I need this field enabled but without cursor)
Otherwise how can change the cursor colour ?
(I dont want to skip tabbing into the textbox i want
the cursor dont seen)
 
Set the Locked property to Yes. User will be able to tab into the field,
but editing is not possible.
 
giannis said:
No. I have try this. The cursor appear again......

If you want the control to have focus, then it will have a cursor. You can move it
to the beginning or end using the SelStart and SelLength properties, but you can't
eliminate it entirely (AFAIK).
 
giannis said:
How can suppress (wipe off) the cursor of a field
in a form without set the propery "Enabled" to No ?
(I need this field enabled but without cursor)
Otherwise how can change the cursor colour ?
(I dont want to skip tabbing into the textbox i want
the cursor dont seen)

This seems an odd thing to want to do, but if you really want to, you
can call the Windows API to do it. I'm no API maven and can't guarantee
that the code sample below is free from errors, but it works in my quick
test:

'----- start of code from form module -----
Option Compare Database
Option Explicit

Private Declare Function apiShowCaret Lib "user32" _
Alias "ShowCaret" _
(ByVal hwnd As Long) _
As Long

Private Declare Function apiHideCaret Lib "user32" _
Alias "HideCaret" _
(ByVal hwnd As Long) _
As Long

Private Declare Function apiGetFocus Lib "user32" _
Alias "GetFocus" _
() As Long


Private Sub Text2_GotFocus()

Dim lngRet As Long

lngRet = apiHideCaret(apiGetFocus())

End Sub


Private Sub Text2_LostFocus()

Dim lngRet As Long

lngRet = apiShowCaret(apiGetFocus())

End Sub
'----- end of code from form module -----

The above code hides the caret when text box Text2 gets the focus and
shows it again when the focus leaves that control. You may well want to
move the API function declarations from the form module to a standard
module, in which case you'd also want to change them from Private to
Public.

Good luck!
 
Back
Top