Get Selected Text

If the user has selected some text in a label or a textbox, how would I get the text? Also, is there a pre-made event handler for when the user selects some text? If not, how would I accomplish that?
[199 byte] By [xRuntime] at [2007-12-25]
# 1

you cannot select text in a label, only on edit/input controls which have been enabled, like a textbox.

I don't think there is an eventhandler for selected text in a textbox

You can get the text selected by using the SelectedText property of the textbox (or even the RichTextBox control I believe). You can even programmatically select some text using the SelectionStart and SelectionLength property of the textbox, and the RTB, control.

Does this help?

ahmedilyas at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

You cannot select Text In labels but you can select text in RichTexbox, If you have any sceneiro where you want to show Label Selection, Just use RichTextBox in the place of label and set its ReadOnly Property to true.

And then you can Programmatically Select and get SelectedText using RichTextBox.Select() and RichTextBox.SelectAll() methods and you can use RichTextBox.SelectedText property to get or set a string to select or string which was selected in either case. Also you can use RichTextBox.SelectionStart and RichTextBox.SelectionLength.

Yes also there in an event SelectionChanged in RichTextBox.

So all you have to do is to use RichTextBox Contols in place of Lables and TextBoxes, Set some properties so they should look like Labels or TextBoxes Respectively.

Both Label and TextBox classes dont provide any way to SelectText nor they raise any Event.

Best Regards,

RizwanSharp at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Thanks, labels was just an example, I thought there would be a univseral method to get selected text, so I put those two controls as examples (without checking if they were actually selectable).
xRuntime at 2007-10-8 > top of Msdn Tech,Windows Forms,Windows Forms General...