Search code examples
user-interfacec#-4.0textbox

C# windows form textbox text select from mouse (to copy, etc...)


I am using C# on Visual studio 2012. I have windows form having textbox. I often need to copy text from textbox field. When i tried to select from mouse it doesn't work, as a workaround i need to use ctrl + a from that particular textbox field. Could you please help me how can i enable it through mouse?

Thanks in advance.


Solution

  • If I understand your question... This should actually be a basic Windows function unless you have the textbox disabled either through code or from the properties list.

    enter image description here

    If by chance you are disabling it in your code you will need to change that by either deleting the code or setting the textbox enable to true.

    Using an example from a WinForm that I am using I can right click and use all the basic Windows text functions.

    enter image description here

    Furthermore, you should be able to do this as well... Using the Mouse Click event for the text box you can automate the whole thing by just clicking on the text inside the text box.

    private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            textBox1.SelectAll();
            textBox1.Copy();
        }
    

    Hope this helps!