ContextMenuStrip 未复制到剪贴板
这可能与其说是问题,不如说是咆哮。也就是说 ContextMenuStrip 是我用过的最糟糕的控件..
以下是我将 ContextMenuStrip (CMS) 添加到 RichTextBox 然后使用鼠标单击显示菜单的过程。
需要点击两次才能显示菜单?为什么是如何使用此控件的第一部分。
接下来,选择文本并单击“复制”后,我导航到相同的表单和 RTB 来执行粘贴。
剪贴板上没有文本?我做错了什么?
以下是可以运行但不使用 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
以下是可以运行但不使用 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
好的,这是一个编辑
我注释掉了 SUB CMS 并将此代码添加到 MouseClick。
并添加到上下文菜单条菜单项复制和粘贴。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论