devxlogo

Emulating Overstrike Mode in Text Boxes

Emulating Overstrike Mode in Text Boxes

Windows text boxes always work in insert mode and don’t provide anoverstrike mode. However, overstrike mode can easily be emulated as shownhere:

 Sub Text1_KeyPress (KeyAscii As Integer) If KeyAscii >= 32 Then If Text1.SelLength = 0 Then If Text1.SelStart < Len(Text1) Then Text1.SelLength = 1 End If End If End If End Sub 

If a key is typed when no text is selected, the code selects thecurrent character by setting the SelLength property to 1, causing it tobe overwritten by the key typed. If the cursor is already at the end ofthe text, setting the SelLength property to 1 is silently ignored. Severalconditions are tested to ensure that a control character (such as Tab orEnter) was not pressed, that the user hasn't already highlighted text tobe replaced, and that the caret is not at the end of the existing text.

See also  Digital Signage Solutions for Agile Software Development Teams
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist