Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[2692] Drag and Drop in Windows Forms - A Primer

Last post 07-05-2008 2:28 AM by konikula. 19 replies.
Page 2 of 2 (20 items) < Previous 1 2
Sort Posts: Previous Next
  • 08-16-2006 2:52 PM In reply to

    • aph_df
    • Not Ranked
    • Joined on 08-16-2006
    • New Member
    • Points 5

    Re: [2692] Drag and Drop in Windows Forms - A Primer

    I am a self taught newbie (the worse sort) so please go gently.

     

    My son has produce code to display and reorder jpeg thumbnails in a ListView and it works well, however, I would prefer Drop and Drag. I have sort of got it to work based on the example and a suggestion to remove 2 lines of code (see below) but it has 2 main problems. Note I am dragging within the same list (reordering) rather than dragging it somewhere else.

     

    1/ Whenever I drop the thumbnail it always ends up at the bottom of the list.

    2/ There is no indication where its about to be dropped.

     

    Finally is there a way to display / bring into view an thumbnail image that has scrolled outside the window?

     

     

        Private Sub ListViewDragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop, ListView1.DragDrop

     

     

            Dim lvItem As ListViewItem

            Dim destItem As ListViewItem

            Dim destLv As ListView = CType(sender, ListView)

            Dim clX As Integer = destLv.PointToClient(New Point(e.X, e.Y)).X

            Dim clY As Integer = destLv.PointToClient(New Point(e.X, e.Y)).Y

            If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem", False) Then

                'dragging a listview item

                lvItem = CType(e.Data.GetData("System.Windows.Forms.ListViewItem"), ListViewItem)

                '#' - destItem = CType(sender, ListView).GetItemAt(clX, clY)

                '#' -            destLv.Items.Insert(destItem.Index, lvItem.Clone)

                lvItem.Remove()

                destLv.Items.Add(lvItem)

            End If

        End Sub

     

    Thanks in advance, Andrew

    • Post Points: 5
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 11-29-2006 10:15 PM In reply to

    • pcmattman
    • Top 150 Contributor
    • Joined on 01-03-2006
    • Fanatic Member
    • Points 1,385

    Re: How to Drag Controls

    If you find a control in VB that has a 'hwnd' property, you can drag it without too much hassle.

    Add the following to the top of the form code:

    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Const HTCAPTION = 2
    Public Const WM_NCLBUTTONDOWN = &HA1



    You then, on the mousemove event, check to see if the mouse is pressed. If so, you call:
    SendMessage( [the hwnd of the control], WM_NCLBUTTONDOWN, HTCAPTION, 0& )

    The control should now be movable.

    gdt_set_gate(5, (unsigned long) &global_tss, sizeof( TSS_t ) + 0xFFFF, 0x89, 0x0F );

    http://www.sourceforge.net/projects/mattise - My hobby operating system (Intel, 32-bit only).
    • Post Points: 5
  • 07-27-2007 11:07 AM In reply to

    Re: [2692] Drag and Drop in Windows Forms - A Primer

    I wanted to write a simple form where the user could add a label to the form, rename it and move the label to where they needed it. Your code was right on the money and I can't thank you enough as it allowed to add a lot more functionality to the process that I never thought of before and it is working a treat.

     

    • Post Points: 5
  • 08-09-2007 9:03 PM In reply to

    • hollowood
    • Not Ranked
    • Joined on 08-09-2007
    • United Kingdom
    • New Member
    • Points 5

    Can a selected (or highlighted) string from a text file be dragged and dropped?

    How to use Drag and Drop to drag a highlighted (or selected) string from a text file and drop it. Thanks.
    • Post Points: 5
  • 07-05-2008 2:28 AM In reply to

    • konikula
    • Top 50 Contributor
    • Joined on 12-19-2005
    • Czech Republic
    • Guru
    • Points 3,725

    Re: [2692] Drag and Drop in Windows Forms - A Primer

    there is problem to select text (text-text example) after you dragged from source textbox it disallows to select some part

    I can advice you, but I have many questions too. support.vb
    • Post Points: 5
Page 2 of 2 (20 items) < Previous 1 2