Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change the cursor in a textbox?

Status
Not open for further replies.

radha83

Programmer
Feb 19, 2002
15
0
0
IN
hi,
i want to change the cursor in a textbox control. tell me how to go abt it?
Radha
 
try playing around with the MousePointer property of the textbox in question... ;)

Phr3-|-
------------------------------------------
ps. visit for some of my muzic...
------------------------------------------
 
Go to the text box property window and select the MousePointer property. You can select one of the listed pointers, or select Custom-99, then go to the MouseIcon property and select a cursor from the graphics folder (I think you have to go to VB's folders Common/Graphics/Cursors). "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
 
thanks,
but i want to change the cursor not the mouse icon.
is it posible? Radha
 
what do u mean by change the cursor not the mose icon......?

Phr3t ------------------------------------------
ps. visit for some of my muzic...
------------------------------------------
phr3t@hotmail.com
 
Rhada,

What do you mean? Are you talking about the caret (blinking cursor at the insertion point)? If so, then in what way do you want to change it?
 
yes. i want to change the caret or the blinking cursor to some other cursor or icon image. Radha
 
Had a nasty feeling you were going to say that. Changing the caret is requires that you resoirt to the API, and that you understand that each window only has one caret, and that VB keeps track of its carets and continually tries to reset them.

So, that being said, here is some example code that will change the caret in a textbox. You need a form with a textbox on it. Then just drop the code onto it:
[tt]
Option Explicit
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function CreateCaret Lib "user32" (ByVal hWnd As Long, ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function ShowCaret Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long

Private Const IMAGE_BITMAP = 0
Private Const LR_LOADFROMFILE = 16
Private Const LR_CREATEDIBSECTION = 8192
Private Const LR_DEFAULTCOLOR As Long = &H0

Private hCaretBitmap As Long

' Create and show a custom caret in window with focus
' If hCaretBitmap is 0, then caret adopts width and height specified
' If hCaretBitmap is not 0 it is assumed to be the handle of a bitmap
' and the caret is switched to that bitmap. Note that, when used as a
' caret, the bitmap is XORed to the screen.
Sub ShowCustomCaret(hCaret As Long, width As Integer, height As Integer)
CreateCaret GetFocus(), hCaret, width, height
ShowCaret GetFocus()
End Sub

Private Sub Form_Load()
Dim sFilename As String
sFilename = "c:\folder.bmp"
hCaretBitmap = LoadImage(0, sFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_DEFAULTCOLOR Or LR_CREATEDIBSECTION)
' Use the following line instead of previous 3 lines if your image source is a picture object of some kind.
' Note, however, that this won't then work in the Load event
' hCaretBitmap = Picture1.Picture
End Sub

' Remember, this only triggers when changing focus within the application, not
' if focus switches from another application - so VB will get a chance to switch
' the caret back.
Private Sub Text1_GotFocus()
' Show custom caret
ShowCustomCaret hCaretBitmap, 0, 0
' Show custom block caret
' ShowCustomCaret 0, 5, 14
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top