Results 1 to 2 of 2

Thread: Drag and Drop

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707

    Talking Drag and Drop

    I have two images(could be n images) and a picture box.
    I need to drap and drop the images into the picture box and then save the picture as an image.

    I have two(2) problems:

    1) When i drag and drop the images into the picture box, they just dissapears on the box

    2) When i drag and drop an image the image dissapear from the original position and i lose it forever

    Where is the code.

    Option Explicit
    Dim frmname As String

    Rem inicio drag
    Dim DY As Single
    Dim DX As Single

    Dim NumColumnas As Integer
    Dim NumFilas As Integer
    Dim bIniciando As Boolean

    'Declaraciones del API para 32 bits
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" _
    (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
    ByVal X As Long, ByVal Y As Long, ByVal cX As Long, ByVal cY As Long, _
    ByVal wFlags As Long) As Long

    Const GWL_STYLE = (-16)
    Const WS_THICKFRAME = &H40000
    '
    Const SWP_DRAWFRAME = &H20
    Const SWP_NOMOVE = &H2
    Const SWP_NOSIZE = &H1
    Const SWP_NOZORDE = &H4
    Rem fin drop

    Private Sub cmdSalir_DragDrop(Source As Control, X As Single, Y As Single)
    'Cancel Drag
    CancelarDrag Source
    End Sub
    Private Sub CambiarEstilo(queControl As Control)
    Dim Style As Long

    On Local Error Resume Next

    Style = GetWindowLong(queControl.hWnd, GWL_STYLE)
    If Err Then
    Err = 0
    MsgBox "El control " & queControl.Name & " no permite que se redimensione", vbInformation
    Exit Sub
    End If
    Style = Style Or WS_THICKFRAME
    Style = SetWindowLong(queControl.hWnd, GWL_STYLE, Style)
    Style = SetWindowPos(queControl.hWnd, _
    Me.hWnd, 0, 0, 0, 0, SWP_NOZORDE Or _
    SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME)

    End Sub
    Private Sub CancelarDrag(Source As Control)
    Source.Visible = True
    Source.Drag vbCancel
    End Sub
    Private Sub EndDragDrop(Source As Control, X As Single, Y As Single, Optional Dest As Object)
    Dim posX As Long
    Dim posY As Long

    If Dest Is Nothing Then
    posX = -30
    posY = -30
    If Source.Container.Name <> frmname Then
    CancelarDrag Source
    Exit Sub
    End If
    Else
    If Dest.Name = Source.Container.Name Then
    posX = -60
    posY = -60
    Else
    If Source.Container.Name <> frmname Then
    CancelarDrag Source
    Exit Sub
    End If

    With Dest
    If .Container.Name = frmname Then
    posX = .Left
    posY = .Top
    Else
    posX = .Container.Left + .Left + 60
    posY = .Container.Top + .Top + 60
    End If
    End With
    End If
    End If

    With Source
    .Visible = True
    .Move posX + X - DX, posY + Y - DY
    .Drag vbEndDrag
    .ZOrder
    End With

    If TypeOf Source Is TextBox Then
    Source.SetFocus
    End If

    End Sub
    Private Sub IniciarDrag(Source As Control, Button As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
    DX = X
    DY = Y
    Source.Drag vbBeginDrag
    'Cambiar a no visible, ya que si no,
    'el form no detectaría que se h soltado,
    'si el puntero del ratón no sale del control.
    Source.Visible = False
    Source.Drag
    End If
    End Sub
    Private Sub Form_Load()
    bIniciando = True
    frmname = Me.Name
    'Redimensionar Controles
    CambiarEstilo image1
    CambiarEstilo image2
    bIniciando = False
    End Sub
    Private Sub image1_DragDrop(Source As Control, X As Single, Y As Single)
    EndDragDrop Source, X, Y, image1
    End Sub
    Private Sub image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    IniciarDrag image1, Button, X, Y
    End Sub
    Private Sub image2_DragDrop(Source As Control, X As Single, Y As Single)
    EndDragDrop Source, X, Y, image2
    End Sub
    Private Sub image2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    IniciarDrag image2, Button, X, Y
    End Sub

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    please enclose your post with code tags. formatted code is *so* much easier to read.
    just put a tag in front of it, and behind it

    Code:
    beep

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