Results 1 to 15 of 15

Thread: how do I use drag and drop?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    how do I use drag and drop?

    I feel stupid asking this, but could someone just tell me how I would use the drag and drop feature? I want the users to be able to drag a bunch of files over into a MDI form
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    HI,

    Not sure what you are asking.

    You don't drop files on to forms as such. You load files into your application and then display their contents, e.g. data in a Datagrid or text in a TextBox etc.

    I do not think there is any automatic drag/drop in .NET (there was in VB6) and it has to be coded. To give you a start, the following creates the collect & drag part for a TextBox. Try the MSDN for the remaining code to prepare the target

    If you want to drag and drop the contents of a TextBox, etc, you:


    set the AllowDrop property of the target to true

    write code to detect the intention to drag/drop e.g. in the MouseMove event of the source TextBox

    If e.Button=0 then exit sub (if no button is pressed)


    Create a new DataObject instance to hold the contents of the source and exit if no data to be dragged

    Dim txtTemp as TextBoxBase=DirectCast(sender, TextBoxBase)
    if txtTemp.TextLength = 0 then Exit Sub

    if e.x>=0 and e.x < txtTemp.Width and e.y>=0 and e.y<tbase.height Exit Sub (check if cursor is still inside control's borders)

    Dim datTemp as new DataObject()
    if txtTemp.SelectionLength>0 then
    datTemp.SetData(dataFormats.text, txtTemp.SelectedText
    Else
    datTemp.SetData(dataFormats.text, txtTemp.Text
    end if


    start the drag operation & wait until it is completed

    Dim effect as DragDropEffects = DragDropEffects.Copy or DragDropEffects.Move
    effect=txtTemp.DoDragDrop(datTemp, effect)

    Delete source contents if required

    If effect = DragDropEffects.Move Then
    If txtTemp.SelectionLength > 0 then
    txtTemp.Text = ""
    Else
    txtTemp.Text = ""
    End if
    End if

    Hope I have not done any typos!!
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    HI,

    I've just seen Edneeis' response. That thread resolution seems a lot simpler than mine. Let us know if it works.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Check the links I provided in here :
    http://www.vbforums.com/showthread.p...hreadid=279378

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Thanks all... kinda busy today but will look at this over the weekend again
    Edneeis, I almost forgot there is a search button thanks
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    I actually wrote a utiiliity using the drag/drop functionality. I will post my code in the morning when I get to work.

    Basically though, you set the control property "allow drop" to true
    and in the "dragLeave" or dragdrop event, that's where you get the action.

  8. #8

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by thephantom
    I actually wrote a utiiliity using the drag/drop functionality. I will post my code in the morning when I get to work.

    Basically though, you set the control property "allow drop" to true
    and in the "dragLeave" or dragdrop event, that's where you get the action.
    would you post it then?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  9. #9
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    sorry it took so long to post. I couldn't locate the file. When anyone downloads this file, you'll need to go through and alter some of the code because it was written with some hard-coding.
    Attached Files Attached Files

  10. #10

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by thephantom
    sorry it took so long to post. I couldn't locate the file. When anyone downloads this file, you'll need to go through and alter some of the code because it was written with some hard-coding.
    thanks, got it working
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  11. #11
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Here is a sample project I ran across on the VB Resource Kit as well.
    Attached Files Attached Files

  12. #12
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Phantom,

    I downloaded the Drag drop project you quoted and, of course it works fine .......BUT Could you please tell me how the drag event of txtLowerRight is fired?

    The code which is fired is in the sub

    VB Code:
    1. Private Sub TextBoxLowerRight_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms

    How is this sub called?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  13. #13

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by taxes
    Hi Phantom,

    I downloaded the Drag drop project you quoted and, of course it works fine .......BUT Could you please tell me how the drag event of txtLowerRight is fired?

    The code which is fired is in the sub

    VB Code:
    1. Private Sub TextBoxLowerRight_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms

    How is this sub called?
    highlight the "Source Text" and drag that text over it. It gets fired after the DragEnter event is fired. If e.Effect isnt modified or is set to e.Effect = DragDropEffects.None in the DragEnter event, then the DragDrop event wont be fired


    thanks phantom for the sample
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  14. #14
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    "highlight the "Source Text" and drag that text over it. It gets fired after the DragEnter event is fired. If e.Effect isnt modified or is set to e.Effect = DragDropEffects.None in the DragEnter event, then the DragDrop event wont be fired"

    Sorry, I did not make myself clear but I have just noticed the answer!!
    I was wondering why the drag/drop method of txtLowerRight fired the sub TextBoxLowerRight_DragDrop but I now notice that the handle of the sub refers to txtLowerRight and looking at other threads I notice that you can have more than one event firing a sub by adding handles.

    Many thanks. I'm learning slowly (and sometimes painfully
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  15. #15

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by taxes
    Hi,

    "highlight the "Source Text" and drag that text over it. It gets fired after the DragEnter event is fired. If e.Effect isnt modified or is set to e.Effect = DragDropEffects.None in the DragEnter event, then the DragDrop event wont be fired"

    Sorry, I did not make myself clear but I have just noticed the answer!!
    I was wondering why the drag/drop method of txtLowerRight fired the sub TextBoxLowerRight_DragDrop but I now notice that the handle of the sub refers to txtLowerRight and looking at other threads I notice that you can have more than one event firing a sub by adding handles.

    Many thanks. I'm learning slowly (and sometimes painfully
    sorry I didnt understand your question either....

    btw if you have one sub which handles more than one controls' event, try to pick a general name for it. For example if txtRight_TextChanged handles the event for 3 textboxes then I would say you better change the sub name to something else, like txtPositions_TextChanged
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width