Solved

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

Posted on 2014-11-28
5
117 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now