DragAction Enumerazione

Definizione

Specifica se e in che modo un'operazione di trascinamento dovrebbe continuare.

public enum class DragAction
[System.Runtime.InteropServices.ComVisible(true)]
public enum DragAction
public enum DragAction
[<System.Runtime.InteropServices.ComVisible(true)>]
type DragAction = 
type DragAction = 
Public Enum DragAction
Ereditarietà
DragAction
Attributi

Campi

Cancel 2

L'operazione viene annullata senza alcun messaggio di trascinamento.

Continue 0

L'operazione continua.

Drop 1

L'operazione sarà interrotta con un'azione di trascinamento.

Esempio

Nell'esempio seguente viene illustrata un'operazione di trascinamento della selezione tra due ListBox controlli. Nell'esempio viene chiamato il DoDragDrop metodo all'avvio dell'azione di trascinamento. L'azione di trascinamento inizia se il mouse è stato spostato più che SystemInformation.DragSize dalla posizione del mouse durante l'evento MouseDown . Il IndexFromPoint metodo viene usato per determinare l'indice dell'elemento da trascinare durante l'evento MouseDown .

L'esempio illustra anche l'uso di cursori personalizzati per l'operazione di trascinamento. Nell'esempio si presuppone che due file 3dwarro.cur di cursore e 3dwno.cur, esistano rispettivamente nella directory dell'applicazione, per il trascinamento personalizzato e i cursori senza rilascio. I cursori personalizzati verranno usati se viene UseCustomCursorsCheckCheckBox controllato. I cursori personalizzati vengono impostati nel GiveFeedback gestore eventi.

Lo stato della tastiera viene valutato nel DragOver gestore eventi per il diritto ListBox, per determinare quale operazione di trascinamento sarà basata sullo stato dei tasti MAIUSC, CTRL, ALT o CTRL+ALT. La posizione in ListBox cui si verificherebbe l'eliminazione viene determinata anche durante l'evento DragOver . Se i dati da eliminare non sono , Stringl'oggetto DragEventArgs.Effect è impostato su DragDropEffects.None. Infine, lo stato dell'eliminazione DropLocationLabelLabelviene visualizzato in .

I dati da eliminare per il diritto ListBox sono determinati nel DragDrop gestore eventi e il String valore viene aggiunto al posto appropriato in ListBox. Se l'operazione di trascinamento si sposta all'esterno dei limiti del modulo, l'operazione di trascinamento viene annullata nel QueryContinueDrag gestore eventi.

Questo estratto di codice illustra l'uso dell'enumerazione DragAction . Vedere il metodo per l'esempio DoDragDrop di codice completo.

void ListDragSource_QueryContinueDrag( Object^ sender, System::Windows::Forms::QueryContinueDragEventArgs^ e )
{
   // Cancel the drag if the mouse moves off the form.
   ListBox^ lb = dynamic_cast<ListBox^>(sender);
   if ( lb != nullptr )
   {
      Form^ f = lb->FindForm();

      // Cancel the drag if the mouse moves off the form. The screenOffset
      // takes into account any desktop bands that may be at the top or left
      // side of the screen.
      if ( ((Control::MousePosition.X - screenOffset.X) < f->DesktopBounds.Left) || ((Control::MousePosition.X - screenOffset.X) > f->DesktopBounds.Right) || ((Control::MousePosition.Y - screenOffset.Y) < f->DesktopBounds.Top) || ((Control::MousePosition.Y - screenOffset.Y) > f->DesktopBounds.Bottom) )
      {
         e->Action = DragAction::Cancel;
      }
   }
}
private void ListDragSource_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = sender as ListBox;

    if (lb != null)
    {
        Form f = lb.FindForm();

        // Cancel the drag if the mouse moves off the form. The screenOffset
        // takes into account any desktop bands that may be at the top or left
        // side of the screen.
        if (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) ||
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) ||
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) ||
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom))
        {
            e.Action = DragAction.Cancel;
        }
    }
}
Private Sub ListDragSource_QueryContinueDrag(ByVal sender As Object, ByVal e As QueryContinueDragEventArgs) Handles ListDragSource.QueryContinueDrag
    ' Cancel the drag if the mouse moves off the form.
    Dim lb As ListBox = CType(sender, ListBox)

    If (lb IsNot Nothing) Then

        Dim f As Form = lb.FindForm()

        ' Cancel the drag if the mouse moves off the form. The screenOffset
        ' takes into account any desktop bands that may be at the top or left
        ' side of the screen.
        If (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) Or
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) Or
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) Or
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) Then

            e.Action = DragAction.Cancel
        End If
    End If
End Sub

Commenti

Questa enumerazione viene usata da QueryContinueDragEventArgs.

Si applica a