Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 684
tunafish24 Avatar asked Oct 13 '11 00:10

tunafish24


People also ask

How do I change text from labels in Windows Forms?

Windows. Forms namespace. Add a Label control to the form - Click Label in the Toolbox and drag it over the forms Designer and drop it in the desired location. If you want to change the display text of the Label, you have to set a new text to the Text property of Label.

What is Label in Windows form?

In Windows Forms, Label control is used to display text on the form and it does not take part in user input or in mouse or keyboard events. The Label is a class and it is defined under System.Windows.Forms namespace.

How do I print text in Windows Forms?

To print text In Visual Studio, double-click the form you want to print from, in the Solution Explorer pane. This opens the Visual Designer. From the Toolbox, double-click the PrintDocument component to add it to the form. This should create a PrintDocument component with the name printDocument1 .


1 Answers

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

like image 160
CharithJ Avatar answered Sep 20 '22 00:09

CharithJ