Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing copy, cut and paste functionality of a textbox

Status
Not open for further replies.

catalina36

Programmer
Aug 28, 2000
36
US
The textbox control has cut, copy and paste functionality built right into it. I understand that this functionality can be accessed via either pop-menu or the appropriate short-cut keys (ctrl+x, ctrl+c, ctrl+v). However, I would like to make this functionality available as regular menu items just as they are in Word. Is there any way to directly call these “methods” from my main menu so that I don’t have to code this behavior myself? I can’t figure out how to do this because cut, copy and paste don’t seem to be methods of the textbox!

TIA
[sig][/sig]
 
I'm not sure, but I think those methods can be found in the Win32 API. If you're not familiar with it, try using the API Text viewer under Programs>Visual Studio>Visual Studio Tools>API Text Viewer. Once in here, go to File>Load Text File and choose WIN32API.TXT. This will give you a list of all the Win32 API function calls.

Hope that helps

Joe [sig][/sig]
 
Sub CutCopyPaste(DoWhat As Integer)
' ActiveForm refers to the active form in the MDI form.
If TypeOf Screen.ActiveControl Is TextBox Then
Select Case DoWhat
Case 0 ' Cut.
' Copy selected text to Clipboard.
Clipboard.SetText Screen.ActiveControl.SelText
' Delete selected text.
Screen.ActiveControl.SelText = ""
Case 1 ' Copy.
' Copy selected text to Clipboard.
Clipboard.SetText Screen.ActiveControl.SelText
Case 2 ' Paste.
' Put Clipboard text in text box.
Screen.ActiveControl.SelText = Clipboard.GetText()
Case 3 ' Delete.
' Delete selected text.
Screen.ActiveControl.SelText = ""
End Select
End If
End Sub

[sig][/sig]
 
Thanks for the responses. Both methods work great.

I was able to piece together the code for the Win32 API from an old Visual Basic 4 Win32 API book I had laying around. I would never have thought to go this route. Pretty slick!

Thanks again to both of you for your help!
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top