Control few VB developers notice that a text box (textbox) control has the Undo property, but this property is convenient for programmers. This is a pretty good feature that is used in the development of commercial software that requires editing text or graphics. Many programs require multiple levels of undo, or some programs require "re-operation" to cancel the last step, and these tedious requirements require complex programming design, but a simple undo property of the TextBox control can easily implement these procedures.
Because the Undo feature is part of a text box control, all you need to do is send a "undo youself" Message to the control. This process can be implemented using API function SendMessage. The declaration of this function is:
Declare Function sendmessage Lib "User32" Alias _
"SendMessageA" (Byvalhwnd as Long, _
Byvalwmsg as Long, byvalwparam as Long, _
LParam as any) as Long
The first parameter is the handle to the accepted message, in this case the HWND property of the TextBox control.
The second parameter is the number that identifies the message. To be able to undo an action, the &HC7 value is usually passed, which also represents the Em_undo constant.
The third and fourth parameters are available for some messages, but in this case it is not used and you can set them to 0.
The value returned by the function depends on the message being sent. Can be omitted in this example.
To really use this technique, create a project with a form that contains a TextBox control and a command button control. Add the following line of code to the Click event Program of the command button control:
SendMessage Text1.hwnd, Em_undo, 0&, 0&
Add a module to the project and add the following code to the module:
Public Const Em_undo = &hc7
Public Declare Function SendMessage Lib "User32" _
Alias "SendMessageA" (Byvalhwnd as Long, _
Byvalwmsg as Long, byvalwparam as Long, _
LParam as any) as Long
When you run this project, enter and edit the text in the TextBox control. As you can see, the button undoes the last step. If nothing can be undone, the message will not work. You can use the Undo property as a menu command to affect the activation of the text box as follows:
If Typeofactivecontrol is TextBox Then
Sendmessageactivecontrol.hwnd, Em_undo, 0&, 0&
End If
If a text box is not activated, the button will not perform any action.
The Undo property of the TextBox control is an absorbing and friendly feature and is very simple to use.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service