-
Hi guys!
I want to add an "Edit" menu in my menu bar of my application. I just want to add basic stuff like cut, copy, paste, and maybe undo too. All my controls are textboxes and combos, so i'll just be cutting and pasting strings and text. How do I go about implementing this?
Also, I want to add a "Help" menu, how do I make those standard help files in most windows applications?
Thanks in advance for all the help :)
-
I use the following for Select All, Cut, Copy and Paste.
Code:
Private Sub mnuSelectAll_Click()
rtfData.SelStart = 0
rtfData.SelLength = Len(rtfData.text)
rtfData.SetFocus
End Sub
Private Sub mnuFileCut_Click()
Clipboard.Clear
Clipboard.SetText rtfData.SelText
rtfData.SelText = ""
rtfData.SetFocus
End Sub
Private Sub mnuFileCopy_Click()
Clipboard.Clear
Clipboard.SetText rtfData.SelText
rtfData.SetFocus
End Sub
Private Sub mnuFilePaste_Click()
rtfData.SelText = Clipboard.GetText()
rtfData.SetFocus
End Sub
The Clipboard object is shared by all Windows applications, so you do not need to declare it in VB.
I found code for UNDO in this forum before. It involves setting up an array to store the keystroke changes.
-
-
Thanks now i know about the clipboard stuff, but the code only works if i only have one text box. I have different controls and textboxes in my application. How do I apply it to all?
-
Thanks jbart
Nevermind I figured it out already! Thanks jbart for pointing me to the right direction, you were a great help :)
-
just wondering, is there a nifty way of keeping track if there is something in the clipboard? I want the paste to be enabled only if there is something in the clipboard. Anyone know a way to do this?
-
To keep track, paste the contents of the clipboard into a variable:
Code:
Dim ClipData As String
ClipData = Clipboard.GetText()
If ClipData <> "" Then
Msgbox "Data on clipboard!"
Else
Msgbox "No data on clipboard!"
End If
-
When working with a RichTextBox, you should use the flag vbCFRTF to store and paste the data in RichText Format.
Code:
Private Sub mnuSelectAll_Click()
rtfData.SelStart = 0
rtfData.SelLength = Len(rtfData.Text)
rtfData.SetFocus
End Sub
Private Sub mnuFileCut_Click()
Clipboard.Clear
Clipboard.SetText rtfData.SelText, vbCFRTF
rtfData.SelText = ""
rtfData.SetFocus
End Sub
Private Sub mnuFileCopy_Click()
Clipboard.Clear
Clipboard.SetText rtfData.SelText, vbCFRTF
rtfData.SetFocus
End Sub
Private Sub mnuFilePaste_Click()
rtfData.SelText = Clipboard.GetText(vbCFRTF)
rtfData.SetFocus
End Sub
-
This is great I always learn something new! Thanks guys! Now all I need is to make a nifty help file, does anyone know where I can get started? Been looking for a tutorial but can't seem to find one, I must suck at this :p