问:如何改变文本框编辑时的默认坚线闪烁光标样式?
答:使用API的CreateCaret函数控制光标的宽度与高度实现

'********* Code Start ********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiCreateCaret Lib "user32" _
        Alias "CreateCaret" _
        (ByVal hWnd As Long, _
        ByVal hBitmap As Long, _
        ByVal nWidth As Long, _
        ByVal nHeight As Long) _
        As Long

Private Declare Function apiShowCaret Lib "user32" _
        Alias "ShowCaret" _
        (ByVal hWnd As Long) _
        As Long
Private Declare Function apiGetFocus Lib "user32" _
        Alias "GetFocus" _
         () As Long
Sub sMakeCaret(ctl As Control, _
                        intX As Integer, _
                        intY As Integer)
Dim hWnd As Long
    hWnd = fhWnd(ctl)
    Call apiCreateCaret(hWnd, 0&, intX, intY)
    Call apiShowCaret(hWnd)
End Sub

       
Function fhWnd(ctl As Control) As Long
    On Error Resume Next
    ctl.SetFocus
    If Err Then
        fhWnd = 0
    Else
        fhWnd = apiGetFocus
    End If
    On Error GoTo 0
End Function
'************ Code End **********

'使用试例:
Private Sub Text0_GotFocus()
    sMakeCaret Me.Text0, 4, 15
End Sub

0 回复,0 引用: 如何改变文本框编辑时的默认坚线闪烁光标样式?

添加回复

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。