Solved

Drag&Drop from a textbox - but still want to select text with the mouse

Posted on 2014-11-28
5
127 Views
Last Modified: 2014-12-01
I'd like to perform a drag&drop from a textbox to another textbox.
If I trap the MouseDown event and start the DoDragDrop then I can perform the drag&drop.
eg.
        private void textBox_Adress_MouseDown(object sender, MouseEventArgs e)
        {
            textBox_Adress.DoDragDrop(textBox_Adress.Text, DragDropEffects.Copy);
        }

Open in new window

Unfortunately this then cripples the ability to select text within the textbox for modifying the contents of the textbox.
So.  How is the simplest way to allow the mouse to select text inside the textbox for editing AND allow the mouse to start a drag&drop of the complete contents of the textbox?
0
Comment
Question by:AndyAinscow
  • 3
5 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40471238
Andy,

I don't do much Windows Forms any more, but I wonder if you use the MouseMove event, checking the Left button, what affect that would have?
0
 
LVL 40
ID: 40471296
Bob is right, you should use the MouseDown event. Look at the examples in the Control.DoDragDrop page of the online help, and you will get all the information that you need to perform the operation, from creating the icon or bitmap that will be used during the drag up to the moment the user drop what he was dragging.
0
 
LVL 44

Author Comment

by:AndyAinscow
ID: 40471353
Hi Bob, that is what I was thinking as one backup plan (I've got a couple of others that are lower down the pecking order).  Check the mouse move and only start the DoDragDrop as the mouse leaves the text box (unless there is a specific event firing on the mouse leaving the control) providing the left button was down.

I asked just in case there was a simple way like:
txtBox.MagicSetting = MagicSettings.On;
and then everything would still work.  I like simple ways to do things.
0
 
LVL 44

Author Comment

by:AndyAinscow
ID: 40471359
There is a MouseLeave event.  I'll look at using that.
0
 
LVL 44

Author Closing Comment

by:AndyAinscow
ID: 40473193
The MouseLeave event didn't work as I hoped so I had to use the MouseMove in the end.   Turned out to be only a few lines of code
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question