Results 1 to 6 of 6

Thread: show blinking cursor text box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    251

    show blinking cursor text box

    I have 2 text box in my form is it possible to show the blinking cursor in both text box when textbox1 is Focused

  2. #2
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: show blinking cursor text box

    No , i don't think this is possible. Blinking cursor only shows or display in the active textbox in the active form or application
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: show blinking cursor text box

    I don't know if thats possible, you could fake a cursor, though it be a lot of work if you want to do it for a multiline textbox, heres a quick hack for a non-multiline textbox.
    Code:
    ' // Make Text1 blink a fake cursor when it loses focus. //
    ' Note: Form scalemode is Twips, Text1 is single-line, 3D, and uses same font properties as form!
    Option Explicit
    
    Private Sub Form_Load()
        Timer1.Interval = 500 ' blink rate
        Timer1.Enabled = False
    End Sub
    
    Private Sub Text1_GotFocus()
        Timer1.Enabled = False
        PicCursor.Visible = False
    End Sub
    
    Private Sub Text1_LostFocus()
        Timer1.Enabled = True
        PicCursor.ZOrder 0
    End Sub
    
    Private Sub Timer1_Timer()
        Dim CurT As Long, CurL As Long
        CurL = 30 + Text1.Left + Me.TextWidth(Mid$(Text1.Text, 1, Text1.SelStart))
        CurT = 30 + Text1.Top
        PicCursor.Move CurL, CurT
        PicCursor.Visible = Not PicCursor.Visible
    End Sub
    Last edited by Edgemeal; Jan 5th, 2010 at 03:18 AM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    251

    Re: show blinking cursor text box

    Thanks man great my blinking cursor instead of going to the next line it takes the text to the next line cursor stay at the tope

    can we do some like

    if keyascii = 13

    then go to the next line

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: show blinking cursor text box

    Quote Originally Posted by bordino View Post
    Thanks man great my blinking cursor instead of going to the next line it takes the text to the next line cursor stay at the tope

    can we do some like

    if keyascii = 13

    then go to the next line
    Not with that code. Play around with this and see if it helps.

    Code:
    '// Make Text1 blink a fake cursor when it loses focus. //
    ' // Note: Form scalemode is Twips.//
    
    Option Explicit
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
    Dim XPos As Long
    Dim YPos As Long
    
    Private Sub Form_Load()
        Timer1.Interval = 500 ' blink rate
        Timer1.Enabled = False
    End Sub
    
    Private Sub Text1_LostFocus()
        Dim CurT As Long, CurL As Long, OffSet3D As Long
        ' if tetxbox is 3D then add 30 twips
        If Text1.Appearance = 1 Then OffSet3D = 30
        ' position pic box
        CurL = Text1.Left + XPos + OffSet3D
        CurT = Text1.Top + YPos + OffSet3D
        PicCursor.Move CurL, CurT
        Timer1.Enabled = True
        PicCursor.ZOrder 0
    End Sub
    
    Private Sub Text1_GotFocus()
        Timer1.Enabled = False
        PicCursor.Visible = False
        SaveCaretPos
    End Sub
    
    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
        SaveCaretPos
    End Sub
    
    Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        SaveCaretPos
    End Sub
    
    Private Sub Timer1_Timer()
        ' blink it
        PicCursor.Visible = Not PicCursor.Visible
    End Sub
    
    Private Sub SaveCaretPos()
        Dim pt As POINTAPI
        ' get caret pos. in text box
        GetCaretPos pt
        'Convert to twips
        XPos = ScaleX(pt.X, vbPixels, vbTwips)
        YPos = ScaleY(pt.Y, vbPixels, vbTwips)
    End Sub
    Just a note, if text1 has scrollbars and it looses focus, then you scroll the textbox without setting focus on text1 then the fake blinking cursor will be in the wrong position. I think you would need to subclass text1 to get the scroll messages and act on those as well if you use this.
    Last edited by Edgemeal; Jan 5th, 2010 at 03:18 AM.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    251

    Re: show blinking cursor text box

    in my text box selstart set to 0 when I type from right to left ok but
    When I press enter instead of the curse go to the next line text placed in next line and cursor stay at the top
    op
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width