下面是关于在菜单条项目上按下鼠标右键以复制菜单项的代码。我还复制了没有格式化的设置文本。我遇到的问题是。它不是拍卖/复制到剪贴板,我不确定为什么?
Private Sub MenuTreeToolStripMenuItem_MouseDown(sender As Object, e As MouseEventArgs) Handles MenuTreeToolStripMenuItem.MouseDown
Select Case MouseButtons
Case MouseButtons.Left
'Left click
Case MouseButtons.Right
'Right click
My.Computer.Clipboard.SetText("This is a test string.", System.Windows.Forms.TextDataFormat.Rtf)
End Select
End Sub
' alt版本在这里
Private Sub MenuTreeToolStripMenuItem_MouseDown(sender As Object, e As MouseEventArgs) Handles MenuTreeToolStripMenuItem.MouseDown
Select Case MouseButtons
Case MouseButtons.Left
'Left click
Case MouseButtons.Right
'Right click
My.Computer.Clipboard.SetText("This is a test string")
End Select
End Sub
修订后的代码
Private Sub MenuTreeToolStripMenuItem_MouseDown(sender As Object, e As MouseEventArgs) Handles MenuTreeToolStripMenuItem.MouseDown
Select Case e.Button
Case e.Button.Left
'Left click
Case e.Button.Right
'Right click
My.Computer.Clipboard.SetText("This is a test string.")
End Select
End Sub
答案 0 :(得分:1)
下面的代码优雅地为我呐喊。
Private Sub MenuTreeToolStripMenuItem_MouseDown(sender As Object, e As MouseEventArgs) Handles MenuTreeToolStripMenuItem.MouseDown
Select Case e.Button
Case Windows.Forms.MouseButtons.Left
'Left click
Case Windows.Forms.MouseButtons.Right
'Right click
My.Computer.Clipboard.SetText("This is a test string.")
End Select
End Sub