ContextMenuStrip 未复制到剪贴板

发布于 2025-01-12 02:50:53 字数 1875 浏览 4 评论 0原文

这可能与其说是问题,不如说是咆哮。也就是说 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文