Is there any way to make a label on a .NET Windows form to be highlightable to allow for the text to be copied. I have attempted to do this with a text box that was made to look like a label, but this results in a flashing cursor.
I think this is pretty darn close:
textBox.BackColor = System.Drawing.SystemColors.Control;
textBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
textBox.ReadOnly = true;
textBox.Text = "This is selectable text";
textBox.MouseUp += new MouseEventHandler(
delegate(object sender, MouseEventArgs e)
{ HideCaret((sender as Control).Handle); });
[DllImport("User32.dll")]
static extern Boolean HideCaret(IntPtr hWnd);
And if you need it to span more than one line:
textBox.Multiline = true;
If you want it to be a predictable, well behaved and standard control with all the keyboard and shortcut support you simply need a textbox. And then the flashing cursor is a normal helpful feature, why fight it?
It's not unusual for selectable static text to show a flashing cursor. If you get the properties of any file in Windows Explorer and select any data in that window, you'll also see a flashing cursor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With