DragAction Enumeration

Definition

Gibt an, wie und ob ein Drag-and-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

Name Wert Beschreibung
Continue 0

Der Vorgang wird fortgesetzt.

Drop 1

Der Vorgang wird mit einem Drop beendet.

Cancel 2

Der Vorgang wird ohne Dropnachricht abgebrochen.

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 beginnt, wenn die Maus während des SystemInformation.DragSize Ereignisses mehr als MouseDown von der Mausposition bewegt wurde. Die IndexFromPoint Methode wird verwendet, um den Index des Elements zu bestimmen, das während des MouseDown Ereignisses gezogen werden soll.

Das Beispiel veranschaulicht auch die Verwendung von benutzerdefinierten Cursorn für den Drag-and-Drop-Vorgang. Im Beispiel wird davon ausgegangen, 3dwarro.cur dass zwei Cursordateien und 3dwno.cur, die im Anwendungsverzeichnis vorhanden sind, für die benutzerdefinierten Mauszeiger bzw. Cursor ohne Drop vorhanden sind. Die benutzerdefinierten Cursor werden verwendet, wenn dies UseCustomCursorsCheckCheckBox aktiviert ist. Die benutzerdefinierten Cursor werden im GiveFeedback Ereignishandler festgelegt.

Der Tastaturzustand wird im DragOver Ereignishandler für die rechte ListBoxSeite ausgewertet, um zu bestimmen, was der Ziehvorgang auf dem Zustand der TASTEN UMSCHALT, STRG, ALT oder STRG+ALT basiert. Die Position in der Stelle, an der ListBox der Abbruch erfolgt, wird auch während des DragOver Ereignisses bestimmt. Wenn es sich bei den zu löschenden Daten nicht um einen StringWert handelt, wird der DragEventArgs.Effect Wert auf DragDropEffects.None festgelegt. Schließlich wird der Status des Drops in der DropLocationLabelLabel.

Die für das Rechte ListBox ablegenden Daten werden im DragDrop Ereignishandler bestimmt, und der String Wert wird an der entsprechenden Stelle in der ListBox. 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. Sehen Sie sich die DoDragDrop Methode für das vollständige Codebeispiel an.

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 Aufzählung wird von QueryContinueDragEventArgs.

Gilt für: