Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Overwrite mode for textbox controls

Total Hit ( 2329)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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:

Click here to copy the following block
' form level variable
Dim overwriteMode As Boolean

Sub 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 If
End Sub

Sub Text1_KeyDown (KeyCode As Integer, Shift As Integer)
  If KeyCode = 45 And Shift = 0 Then
    overwriteMode = Not overwriteMode
  End If
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.