Is it possible to select text on a Windows form label?

tunafish24 picture tunafish24 · Oct 13, 2011 · Viewed 46k times · Source

Is it possible to highlight/select part of text in a Windows Form label control? I know its possible with RTFtextbox control but that using that control would be overkill as I need to create many instances of the label.

Answer

CharithJ picture CharithJ · Oct 13, 2011

Is it possible to select text on a Windows form label? - NO (At least no easy way without overriding Label.Paint method)

You can easily change a TextBox for this purpose.

TextBox1.Text = "Hello, Select Me";
TextBox1.ReadOnly = true;
TextBox1.BorderStyle = 0;
TextBox1.BackColor = this.BackColor;
TextBox1.TabStop = false;
TextBox1.Multiline = True; // If needed

Don't believe? here is an example for you.

enter image description here

Option 2 (If you just want to enable copy label text)

Double clicking on the label copies the text to clipboard. This is the default winforms Label functionality. You can add a toolTip control to improve the usability if you like.

enter image description here