Pregunta

When I double-click a LinkLabel in WindowsForms it copies its text; how can I prevent this?

BTW, it's a .Net 2.0 application, if that makes any difference.

Thanks

¿Fue útil?

Solución

You can always clear the clipboard using :

Clipboard.Clear();

Update :

You can use this code in mouse double click event.

Try this :

private void linkLabel1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        Clipboard.Clear();
    }

Update 2 :

Use these following codes it won't copy value of linklable and also it keeps your clipboard. you must use these codes with mouse enter event and mouse double click event.

Try this :

public string str;

    private void linkLabel1_MouseEnter(object sender, EventArgs e)
    {
        str = Clipboard.GetText();
        linkLabel1.MouseDoubleClick+=new MouseEventHandler(linkLabel1_MouseDoubleClick);
    }

    private void linkLabel1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        Clipboard.SetText(str);
    }

Otros consejos

It seems that this behaviour is built into the LinkLabel and that there's no way to override it.

Testing reveals the clipboard has already changed by the time the MouseDoubleClick event is triggered.

FWIW, I've never needed this control - a regular Label with some styling and use of the MouseEnter/MouseLeave events has served me well in many projects.

What you can do is to create your own label and derive it from Control as public class MyLabel : Control and then draw the text in it yourself as

protected override void OnPaint(PaintEventArgs e)
{
        SolidBrush TextBrush = new SolidBrush(this.ForeColor);
        TextRenderer.DrawText(e.Graphics, this.Text, this.Font, this.ClientRectangle, this.ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter );
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top