This may be more of a RANT than question. That said the ContextMenuStrip is the worst control I have ever used..
Here is the process I added a ContextMenuStrip (CMS) to a RichTextBox then used a mouse click to show the menu.
It takes two clicks to get the menu to show? WHY is the first part of how to use this control.
Next after selecting the text and clicking COPY I navigate to the same form and RTB to do a PASTE.
NO TEXT on the clipboard? What am I doing wrong?
Here is the code and other code that works but does not use the ContextMenuStrip.
Public Sub CMS()
Dim contextMenu As ContextMenuStrip = New System.Windows.Forms.ContextMenuStrip()
Dim menuItem As New ToolStripMenuItem("Cut")
contextMenu.Items.Add(menuItem)
menuItem = New ToolStripMenuItem("Copy")
contextMenu.Items.Add(menuItem)
menuItem = New ToolStripMenuItem("Paste")
contextMenu.Items.Add(menuItem)
Me.ContextMenuStrip1 = contextMenu
End Sub
Private Sub rtbNotes_MouseClick(sender As Object, e As EventArgs) Handles rtbNotes.MouseClick
'ContextMenuStrip1.Show(Me.rtbNotes.Location)'This show the menu 2 inches away from the form?
rtbNotes.SelectAll()
ContextMenuStrip1.Show(Me, Me.PointToClient(MousePosition))
CMS()
End Sub
Here is code that works it does not use the CMS.
Private Sub rtbNotes_Click(sender As Object, e As EventArgs) Handles rtbNotes.Click
If gvActionType = "View" Then
Clipboard.SetText(rtbNotes.Text)
MsgBox("If Fire")
End If
If gvActionType = "Add" Then
If Clipboard.ContainsText(TextDataFormat.Text) Then
rtbNotes.SelectedText = Clipboard.GetData(DataFormats.Text).ToString()
End If
End If
End Sub
OK here is an EDIT
I commented out the SUB CMS and added this code to the MouseClick.
And added to the Context Menu Strip Menu Items COPY and Paste.
If gvActionType = "View" Then
Clipboard.SetText(rtbNotes.Text)
End If
If gvActionType = "Add" Then
If Clipboard.ContainsText(TextDataFormat.Text) Then
rtbNotes.SelectedText = Clipboard.GetData(DataFormats.Text).ToString()
End If
End If