Making a label's text selectable

curiouswebster
curiouswebster used Ask the Experts™
on
I have a text label and need the user to be able to select the text in the label and copy it to the clipboard.

What property on the label do I set for this?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance programmer / Consultant
Commented:
You can't - a label doesn't work that way.
You could use a textbox (read only) instead.
curiouswebsterSoftware Engineer

Author

Commented:
thanks
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
You could assign a ContextMenuStrip to the Label(s) with a "Copy" option that puts the Label's Text() value onto the Clipboard:
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            label1.ContextMenuStrip = contextMenuStrip1;
            label2.ContextMenuStrip = contextMenuStrip1;
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Label lbl = (Label)contextMenuStrip1.SourceControl;
            Clipboard.SetText(lbl.Text);
        }

    }

Open in new window

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
*Then you Right Click the Label...
curiouswebsterSoftware Engineer

Author

Commented:
sweet!
AndyAinscowFreelance programmer / Consultant

Commented:
Wouldn't that need to be done for each and every label you wanted to copy the text from?

Nice work around though.


@newbieweb - If you think the suggestion by Idle_mind is what you require then hit the request attention link and ask for a reallocation of the questions answer.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
I don't need any points.

You could wire up all the Labels at run-time using a recursive search.
curiouswebsterSoftware Engineer

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial