Show a custom caret

VB gives you no control on the size of the text caret. At times it can be necessary to change its size, however, for example when you want to signal that the TextBox is in overwrite mode. Here’s a routine that does the trick:

Private Declare Function GetFocus Lib "user32" () As LongPrivate Declare Function CreateCaret Lib "user32" (ByVal hWnd As Long, _    ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As LongPrivate Declare Function ShowCaret Lib "user32" (ByVal hWnd As Long) As Long' Create and show a caret of given sizeSub ShowCustomCaret(ByVal width As Integer, ByVal height As Integer)    CreateCaret GetFocus(), 0, width, height    ShowCaret GetFocus()End Sub

The above routine is meant to be invoked from within the GotFocus event of all textboxes on the form. This is necessary because VB has the bad habit to destroy any caret when the focus move to another field:

Private Sub Text1_GotFocus()    ' Show a caret 5 pixelz wide and 14 pixels tall    ShowCustomCaret 5, 14End Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may