Overwrite mode for textbox controls

By default, textbox controls work in insert mode, where each new character never overwrites existing ones. If you wish to implement overwrite mode you can take advantage of the fact that characters pressed by the user replace the currently selected text, if any.

You need to declare a form-level variable that holds the current mode, and modify the KeyPress event of the text box control. You also need to add some code to the KeyDown event procedure, in order to trap the INS key and pass from insert mode to overwrite mode and vice versa:

' form level variableDim overwriteMode As BooleanSub Text1_KeyPress (KeyAscii As Integer)    If overwriteMode And KeyAscii >= 32 And Text1.SelLength = 0 Then        ' we are in overwrite mode, the user hasn't pressed a        ' control key and there's no text currently highlighted        If Mid$(Text1.Text, Text1.SelStart + 1, 1) <> vbCr Then            ' we are not at the end of the current line of text            ' select the next character, so that it will be replaced by            ' key typed by the end user            Text1.SelLength = 1        End If    End IfEnd SubSub Text1_KeyDown (KeyCode As Integer, Shift As Integer)    If KeyCode = 45 And Shift = 0 Then        overwriteMode = Not overwriteMode    End IfEnd Sub

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

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

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