Shell   20-05-2023, 22:57
#1
Buenas!.

Viendo un ejemplo de Cogier sobre Drag y Drop, creé algo similar. Pero cuando el objeto es arrastrado fuera del lugar donde debe estar,
este se borra y se elimina de su contenedor de origen.

Tengo un panel con tres etiquetas. Cada etiqueta tiene una palabra que forman una frase desordenada.
Se trata de llevar cada etiqueta al otro panel y que la frase se pueda ver ordenada.

Una vez el control se ha arrastrado o creado en el otro panel, debe ser eliminado del panel de origen.

Para probar el efecto debe ser arrastrado fuera de su contenedor y que no sea el panel 2.

[Imagen: xFFwNB5.png]

Al pulsar el botón de check se comprueba si el orden de la frase es correcto.

Este es el código.

Código:
Private aphrase As String[] = ["Order", "the", "phrase"]
Private tobject As Object
Private stext As String

Public Sub Form_Open()
 
  Dim lb As Label
  Dim adisorderphrase As String[]
 
  adisorderphrase = aphrase.Copy()
  adisorderphrase.Shuffle()
 
  Panel1.Arrangement = Arrange.Column
 
  For ICount As Integer = 0 To adisorderphrase.Max
    lb = New Label(Panel1) As "words"
    With lb
      .text = adisorderphrase[ICount]
      .Font.Size = 18
      .Alignment = Align.Center
      .AutoResize = True
      .Padding = 5
      .Border = Border.Plain
    End With     
  Next
 
End

Public Sub words_enter()
 
  tobject = Last  
  stext = Last.text
 
End

Public Sub words_MouseDrag()
 
  If Mouse.left Then    
    Last.Drag(Last.text)  
    'If your drag to any place the control is deleted. :(
    Last.Delete
  Endif
 
End

Public Sub Panels_Drop()
 
  Dim lb As Label
    
  If Drag.type = Drag.Text Then     
    lb = New Label(Last) As "words"
    With lb
      .Text = Drag.Data      
      .AutoResize = True
      .W = Drag.Source.w
      .H = Drag.Source.h
      .Border = Border.Plain
      .Font.Size = Drag.Source.Font.Size
      .Padding = 5
    End With    
  Endif
  'Drag.Source.Delete
  'Is impossible delete the object here, the control is being dragged
 
End

Public Sub Button1_Click()
 
  Dim wrong As Boolean
    
  If Panel2.Children.Count = aphrase.Count Then
    For r As Integer = 0 To aphrase.Max
      tobject = Panel2.Children[r]
      If aphrase[r] <> tobject.text Then
        wrong = True
        Break
      Endif
    Next    
    If wrong Then
      Message.Error(("The order of words isn't correct"), "OK")      
    Else
      Message.Info(("The order of words is correct"), "OK")
    Endif  
  Else
    Message.Error(("There aren't enough words on the panel"), "OK")
  Endif

End

Saludos
Última modificación: 21-05-2023, 21:24 por Shell.

"El conocimiento es la mejor inversión que se puede hacer" - Abraham Lincoln
  
Usuarios navegando en este tema:
Powered By MyBB, © 2002-2025 MyBB Group.
Made with by Curves UI.