Inherit Context Menu

martialarts

Regular
Joined
Jun 20, 2003
Messages
59
Location
Chicago Area
Hi. I am using VB.net and am trying to remove/disable copy in the right-click context menu WITHOUT losing the undo, paste, delete, and select all functionality. I have tried creating my own context menu but I could not figure out if there is a way to inherit the default functions like undo, paste, delete, and select all. I also could not figure out if there was a way to call the functions from my new context menu. Any ideas will be greatly appreaciated. Thanks!
 
Solution

Somehow in all my efforts I overlooked the simple solution... so here it is for anyone who might be wondering. All that needed to be done was to create a new context menu, which I chose to do in the form designer, and set it as the context menu in the properties for the control you want a custom context menu for. Then each event for the new context menu should be set individually as I have done in the following events:

Code:
Private Sub Menu3Paste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
        TextBoxEditable.Paste()
    End Sub

Private Sub Menu1Undo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        TextBoxEditable.Undo()
    End Sub

Private Sub Menu5SelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
        TextBoxEditable.SelectAll()
    End Sub

There didn't seem to be a builtin function for Delete, but I didn't consider that an important part of the context menu anyway, so I didn't take the time to write that in. Also, I didn't take the time to figure out how to make the items of the context menu enable and disable based on where or not the clipboard contains something, etc.

Since my point in making a new context menu was to remove Copy and Cut, I also added code to disable Control-C and Control-X. That code is below:

Code:
Private Sub TextBoxEditable_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxEditable.KeyPress
        'Disables Control-C copying and Control-X cutting
        MessageBox.Show(Convert.ToInt32(e.KeyChar))
        If Convert.ToInt32(e.KeyChar) = 3 Or Convert.ToInt32(e.KeyChar) = 24 Then
            e.Handled = True
            Beep()
        End If
    End Sub
 
Back
Top