DragAction Enumeration

Definition

Gibt an, wie und ob ein Drag & Drop-Vorgang fortgesetzt werden soll.

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
Vererbung
DragAction
Attribute

Felder

Cancel 2

Die Operation wird ohne eine Bestätigung des Ablegevorgangs abgebrochen.

Continue 0

Die Operation wird fortgesetzt.

Drop 1

Die Operation wird mit einem Ablegevorgang beendet.

Beispiele

Im folgenden Beispiel wird ein Drag-and-Drop-Vorgang zwischen zwei ListBox Steuerelementen veranschaulicht. Im Beispiel wird die DoDragDrop -Methode aufgerufen, wenn die Ziehaktion gestartet wird. Die Ziehaktion wird gestartet, wenn sich die Maus während MouseDown des Ereignisses mehr als SystemInformation.DragSize von der Mausposition bewegt hat. Die IndexFromPoint -Methode wird verwendet, um den Index des Elements zu bestimmen, das während des Ereignisses MouseDown gezogen werden soll.

Das Beispiel veranschaulicht auch die Verwendung benutzerdefinierter Cursor für den Drag-and-Drop-Vorgang. Im Beispiel wird davon ausgegangen, dass zwei Cursordateien und 3dwarro.cur3dwno.curim Anwendungsverzeichnis für die benutzerdefinierten Cursor drag und no drop vorhanden sind. Die benutzerdefinierten Cursor werden verwendet, wenn die UseCustomCursorsCheckCheckBox aktiviert ist. Die benutzerdefinierten Cursor werden im GiveFeedback Ereignishandler festgelegt.

Der Tastaturzustand wird im DragOver Ereignishandler für die rechte ListBoxausgewertet, um zu bestimmen, welcher Ziehvorgang auf der Grundlage des Zustands der UMSCHALT-, STRG-, ALT- oder STRG+ALT-TASTEN erfolgt. Die Position in der, an der ListBox der Abbruch erfolgen würde, wird auch während des Ereignisses DragOver bestimmt. Wenn die zu löschenden Daten keine Stringsind, wird auf DragEventArgs.EffectDragDropEffects.Nonefestgelegt. Schließlich wird die status des Drops im DropLocationLabelLabelangezeigt.

Die für die rechte ListBox Seite zu löschenden Daten werden im DragDrop -Ereignishandler bestimmt, und der String Wert wird an der entsprechenden Stelle im ListBoxhinzugefügt. Wenn der Ziehvorgang außerhalb der Grenzen des Formulars verschoben wird, wird der Drag-and-Drop-Vorgang im QueryContinueDrag Ereignishandler abgebrochen.

Dieser Codeauszug veranschaulicht die Verwendung der DragAction -Enumeration. DoDragDrop Das vollständige Codebeispiel finden Sie in der -Methode.

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

Hinweise

Diese Enumeration wird von QueryContinueDragEventArgsverwendet.

Gilt für: