Freigeben über


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

Cancel 2

Der Vorgang wird ohne Dropnachricht abgebrochen.

Continue 0

Der Vorgang wird fortgesetzt.

Drop 1

Der Vorgang wird mit einem Drop 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 beginnt, wenn die Maus während des MouseDown Ereignisses mehr als SystemInformation.DragSize von der Mausposition verschoben hat. 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, dass zwei Cursordateien, 3dwarro.cur und 3dwno.cur, im Anwendungsverzeichnis vorhanden sind, für die benutzerdefinierten Mauszeiger bzw. Cursor ohne Drop. 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 richtige ListBoxausgewertet, um zu bestimmen, welche Ziehoperation auf dem Zustand der UMSCHALTTASTE, STRG, ALT oder STRG+ALT basiert. Die Position in der ListBox, an der der Abbruch erfolgen würde, wird auch während des DragOver-Ereignisses bestimmt. Wenn die zu löschenden Daten keine Stringsind, wird die DragEventArgs.Effect auf DragDropEffects.Nonefestgelegt. Schließlich wird der Status des Drops im DropLocationLabelLabelangezeigt.

Die für den richtigen ListBox 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-Aufzählung. Die DoDragDrop-Methode finden Sie im vollständigen Codebeispiel.

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 QueryContinueDragEventArgsverwendet.

Gilt für: