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

Undo changes in a TextBox control

Total Hit ( 3816)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The TextBox control supports the capability to undo changes, but there is no property or method that exposes this feature. You can achieve the same goal with a a set of messages.

Click here to copy the following block
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
  hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  lParam As Any) As Long
Const EM_CANUNDO = &HC6
Const EM_UNDO = &HC7
Const EM_EMPTYUNDOBUFFER = &HCD

The EM_CANUNDO message returns a non-zero value if the contents of the TextBox control can undone. The EM_UNDO message actually undoes all changes:. The following code demonstrates how you can use these messages in a typical Edit menu:

Click here to copy the following block
Private Sub mnuEdit_Click()
  If TypeOf ActiveControl Is TextBox Then
    ' check whether changes to the current
    ' TextBox control can be undone
    mnuEditUndo.Enabled = SendMessage(ActiveControl.hWnd, EM_CANUNDO, 0, _
      ByVal 0&)
  Else
    ' in all other cases, disable this menu command
    mnuEditUndo.Enabled = False
  End If
End Sub

Private Sub mnuEditUndo_Click()
  ' Undo the most recent edit operation on the active control
  ' (no need to use TypeOf...Is to check the control's type)
  SendMessage ActiveControl.hWnd, EM_UNDO, 0, ByVal 0&
End Sub

Finally, the EM_EMPTYUNDOBUFFER clears the internal undo buffer, so that the user can't undo changes.

Click here to copy the following block
SendMessage ActiveControl.hWnd, EM_EMPTYUNDOBUFFER, 0, ByVal 0&


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.