Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 6, 1997

Emulating Overstrike Mode in Text Boxes

Windows text boxes always work in insert mode and don't provide an overstrike mode. However, overstrike mode can easily be emulated as shown here:
 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 the current character by setting the SelLength property to 1, causing it to be overwritten by the key typed. If the cursor is already at the end of the text, setting the SelLength property to 1 is silently ignored. Several conditions are tested to ensure that a control character (such as Tab or Enter) was not pressed, that the user hasn't already highlighted text to be replaced, and that the caret is not at the end of the existing text.
Jonathan Wood
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date