Solved

Changing the cursor in a textbox.

Posted on 2004-10-25
446 Views
Last Modified: 2013-12-26
Hi,
how can i change the cursor that blinks in a textbox,
from a vertical one to horizontal - like dos?
but what i realy need is that the cursor will be like a small green sqaure that when
i move the cursor with the left or right key he will highlight the next letter in the textbox.
thanks...
0
Question by:KinGuy
    5 Comments
     
    LVL 48

    Accepted Solution

    by:
    Try use CreateCaret API:

    Example:

    'On form1 place 2 textboxes (with a height for a couple of lines) and 1 picturebox.
    'Select a bitmap for the picturebox and set the autosize on true.
    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 GetFocus Lib "user32" () As Long
    Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: KPDTeam@Allapi.net

        'Execute the app. (F5) and you'll see the difference of the cursorshapes.
    End Sub
    Sub Text1_GotFocus()
        'retrieve the window which has the focus
        h& = GetFocus&()
        'retrieve the handle of our picture
        b& = Picture1.Picture
        'Create a new cursor
        '(handle, bitmap 0=none, width, height)
        Call CreateCaret(h&, b&, 10, 10)
        'Show our new cursor
        X& = ShowCaret&(h&)
    End Sub
    Private Sub Text2_GotFocus()
        'retrieve the window which has the focus
        h& = GetFocus&()
        'Create a new cursor
        Call CreateCaret(h&, 0, 30, 30)
        'Show the new cursor
        X& = ShowCaret&(h&)
    End Sub
    0
     

    Author Comment

    by:KinGuy
    Thank you for your comment ryancys, but can i stop it from blinking?
    Guy
    0
     
    LVL 48

    Expert Comment

    by:Ryan Chong
    >>but can i stop it from blinking
    Try look for the SetCaretBlinkTime API ?

    Example:

    Private Declare Function SetCaretBlinkTime Lib "user32" (ByVal wMSeconds As Long) As Long
    Private Declare Function GetCaretBlinkTime Lib "user32" () As Long
    Dim nOldBT As Long
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: KPDTeam@allapi.net
        'retrieve the current caret blinktime
        nOldBT = GetCaretBlinkTime
        'set the new caret blinktime
        SetCaretBlinkTime 1
        'When the form is loaded, open a text-editor and check out the caret blinktime
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        'restore the old caret blinktime
        SetCaretBlinkTime nOldBT
    End Sub
    0
     
    LVL 8

    Expert Comment

    by:Ashutosh Vyas
    Try using the SelStart and SelLength properties of the textbox.
    This highlights the text in the textbox.
    Use these on your keydown events.

    KeyCode = 39 for UP
    Keycode = 37 for DOWN
    0
     

    Author Comment

    by:KinGuy
    Hi, i know i weren't here for a long time but army is army and you can't do nothing about it.
    thank you all guys but i need to make a carret like dos. that blinks and that is horizontal. and it needs to be in a textbox.
    can i do that?

    Thanks,
    KinGuy
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now