locked
Drag and drop operation for textbox controls... RRS feed

  • Question

  • hi,

       In my application i have two textboxes(say textBox1 and textBox2). how i can perform drag and drop opertion for these two textboxes in wpf.

       The text from first text should get copied in the second textbox when user clicks in the first textbox and releases in the second one using mouse button.

    Thanks,
    IamHuM
    Sunday, April 5, 2009 12:46 PM

Answers

  • Hi,

    I suppose you are looking for a preview adorner.

    I implemented it with reference to this site,

    http://www.codeproject.com/KB/WPF/ListViewDragDropManager.aspx

    To implement preview adorner, you need to get the adorner layer.

    Create a rectangle of the same size of your textbox. Make use of visualbrush to copy the image of the textbox into the rectangle which will act as the preview.

    As for the positioning of the preview while dragging, the site willl be a good reference.

    Hope this helps.
    • Marked as answer by Tao Liang Wednesday, April 8, 2009 2:04 AM
    Wednesday, April 8, 2009 12:54 AM

All replies

  • The WPF TextBox controls have drag and drop support by default. Selecting some text from textBox1 and dragging it to textBox2 should work out of the box. You can hold down the control key while dragging to cause a copy instead of a move (this is the standard behavior).
    • Proposed as answer by J_________ Monday, April 6, 2009 5:01 PM
    • Marked as answer by Tao Liang Tuesday, April 7, 2009 3:24 AM
    • Unmarked as answer by IamHuM Tuesday, April 7, 2009 4:26 PM
    Monday, April 6, 2009 5:01 PM
  • Hi Juhani,

         Thanks for the reply.
         Actually i have to replace a old application which is having drag and drop support from one textbox to other. So i have to replicate the same thing.

         Is there is any work around to imaplement same...? Please suggest.

    Thanks in advance,
    IamHuM
    Monday, April 6, 2009 6:50 PM
  • As Torkkola mentioned, you do not have to do anything.
    Just have two TextBox, the drag and drop is supported default.
    Tuesday, April 7, 2009 3:25 AM
  • hi All,

           I checked the textbox drag and drop from one to another using CTRL key... and its working. But my actual requirement is to show the text which i am dragging with less opacity. It will be like text is displayed while moving with less opacity from one textbox to another. So i thought drag and drop i should try first and then think of showing text while moving from one textbox to another.

          So please suggest how i can do this.

    Thanks in advance,
    IamHuM
    Tuesday, April 7, 2009 4:18 PM
  • You can use this example code to drag images around like the shell does (Icons, Bitmaps, UIElements, etc):
    linky

    With that code, you could probably override/handle the TextBox's drag methods to call that manager class (which will update the drag image around).
    Tuesday, April 7, 2009 4:45 PM
  • Hi,

    I suppose you are looking for a preview adorner.

    I implemented it with reference to this site,

    http://www.codeproject.com/KB/WPF/ListViewDragDropManager.aspx

    To implement preview adorner, you need to get the adorner layer.

    Create a rectangle of the same size of your textbox. Make use of visualbrush to copy the image of the textbox into the rectangle which will act as the preview.

    As for the positioning of the preview while dragging, the site willl be a good reference.

    Hope this helps.
    • Marked as answer by Tao Liang Wednesday, April 8, 2009 2:04 AM
    Wednesday, April 8, 2009 12:54 AM
  • The only problem I see with using adorners for drag and drop previewing, is that they don't work outside of your app.
    Thursday, April 9, 2009 8:14 PM