Solved

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

Posted on 2014-11-28
5
129 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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