Change caret size and blink rate

Change caret size and blink rate

You can alter the size of the caret (this is the name of the cursor within text boxes, not to be confused with the mouse cursor), for instance to ease visibility on notebook computers, or to signal that the text box is in overwrite mode. All you need is a couple of API functions:

Declare Function CreateCaret Lib "user32" (ByVal hWnd As Long, _    ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As LongDeclare Function ShowCaret Lib "user32" (ByVal hWnd As Long) As LongDeclare Function SetCaretBlinkTime Lib "user32" (ByVal wMSeconds As Long) As _    LongDeclare Function GetCaretBlinkTime Lib "user32" () As LongSub ShowCustomCaret(ByVal width As Integer, ByVal height As Integer)    On Error Resume Next    With Screen.ActiveForm.ActiveControl        CreateCaret .hWnd, 0, width, height        ShowCaret .hWnd    End WithEnd Sub

The second argument to CreateCaret is the handle of a bitmap, a feature that is not used in the above routine. The best place to call the ShowCustomCaret procedure is from within the GotFocus event of a text box:

Sub Text1_GotFocus()    ' show a block cursor    ShowCustomCaret 6, 14End Sub

Unfortunately, Visual Basic tends to restore the default caret each time a text box gets the input focus, so we should insert a call to ShowCustomCaret routine in the GotFocus of all the text boxes on the form. This won’t suffice, however, if the user switches to another application and then back to this form, because in that case no event is fired and we have no chance to re-enforce our custom cursor.

There are two more API functions that deal with carets: GetCaretBlinkTime returns the blink rate of the caret in milliseconds, while SetCaretBlinkTime can change it. Please note, however, that the caret is a shared resource, so you should always restore the blink rate to the original value in the Unload event of the form.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as