有没有什么办法禁用"双击复制"一个.NET标签的功能? [英] Is there any way to disable the "double-click to copy" functionality of a .NET label?

查看:305
本文介绍了有没有什么办法禁用"双击复制"一个.NET标签的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实在是烦人。我使用的标注为列表项的用户控件,用户可以单击它,选择列表项并双击它,将其重命名的一部分。但是,如果您在剪贴板中有一个名字,双击标签将它与标签的文本替换!

This is really annoying. I'm using the label as part of a list item user control, where the user can click it to select the list item and double-click it to rename it. However, if you had a name in the clipboard, double-clicking the label will replace it with the text of the label!

我还检查应用程序的其它标签,他们也将复制到剪贴板上双击。我没有写任何剪贴板code这个计划,我现在用的是标准的.NET标签。

I've also check the other labels in the application, and they will also copy to the clipboard on a doubleclick. I have not written any clipboard code in this program, and I am using the standard .NET labels.

有没有方法来禁用此功能?

Is there any way to disable this functionality?

推荐答案

我能够使用给出其他答案的组合来做到这一点。尝试创建这个派生类和替换你想用它禁用剪贴板功能的任何标签:

I was able to do it using a combination of the other answers given. Try creating this derived class and replace any labels you wish to disable the clipboard functionality with it:

Public Class LabelWithOptionalCopyTextOnDoubleClick
    Inherits Label

    Private Const WM_LBUTTONDCLICK As Integer = &H203

    Private clipboardText As String

    <DefaultValue(False)> _
    <Description("Overrides default behavior of Label to copy label text to clipboard on double click")> _
    Public Property CopyTextOnDoubleClick As Boolean

    Protected Overrides Sub OnDoubleClick(e As System.EventArgs)
        If Not String.IsNullOrEmpty(clipboardText) Then Clipboard.SetData(DataFormats.Text, clipboardText)
        clipboardText = Nothing
        MyBase.OnDoubleClick(e)
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If Not CopyTextOnDoubleClick Then
            If m.Msg = WM_LBUTTONDCLICK Then
                Dim d As IDataObject = Clipboard.GetDataObject() 
                If d.GetDataPresent(DataFormats.Text) Then
                    clipboardText = d.GetData(DataFormats.Text)
                End If
            End If
        End If

        MyBase.WndProc(m)
    End Sub

End Class

这篇关于有没有什么办法禁用&QUOT;双击复制&QUOT;一个.NET标签的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆