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
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
' 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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.