Freigeben über


QueryContinueDragEventArgs.Action-Eigenschaft

Ruft den Status eines Drag & Drop-Vorgangs ab oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property Action As DragAction
'Usage
Dim instance As QueryContinueDragEventArgs
Dim value As DragAction

value = instance.Action

instance.Action = value
public DragAction Action { get; set; }
public:
property DragAction Action {
    DragAction get ();
    void set (DragAction value);
}
/** @property */
public DragAction get_Action ()

/** @property */
public void set_Action (DragAction value)
public function get Action () : DragAction

public function set Action (value : DragAction)

Eigenschaftenwert

Ein DragAction-Wert.

Hinweise

Wenn ESC gedrückt wurde, legt das QueryContinueDrag-Ereignis Action standardmäßig auf DragAction.Cancel fest. Außerdem wird Action auf DragAction.Drop festgelegt, wenn die linke, mittlere oder rechte Maustaste gedrückt wurde.

Beispiel

Im folgenden Beispiel wird ein Drag & Drop-Vorgang zwischen zwei ListBox-Steuerelementen veranschaulicht. In diesem Beispiel wird die DoDragDrop-Methode aufgerufen, wenn der Ziehvorgang begonnen wird. Der Ziehvorgang beginnt, wenn die Maus um mehr als SystemInformation.DragSize von der Mausposition während des MouseDown-Ereignisses verschoben wurde. Mit der IndexFromPoint-Methode kann der Index des im MouseDown-Ereignis zu ziehenden Elements bestimmt werden.

Im Beispiel wird außerdem die Verwendung benutzerdefinierter Cursor in einem Drag & Drop-Vorgang veranschaulicht. Im Beispiel wird davon ausgegangen, dass die beiden Cursordateien 3dwarro.cur und 3dwno.cur für den benutzerdefinierten Ziehcursor bzw. den Cursor, der angezeigt wird, wenn ein Ablegen nicht möglich ist, im Anwendungsverzeichnis vorhanden sind. Die benutzerdefinierten Cursor werden verwendet, wenn die UseCustomCursorsCheckCheckBox aktiviert wurde. Ein benutzerdefinierter Cursor wird im GiveFeedback-Ereignishandler festgelegt.

Der Tastaturzustand wird vom DragOver-Ereignishandler für die rechte ListBox ausgewertet, um je nach Zustand der UMSCHALTTASTE oder von STRG, ALT bzw. STRG+ALT den auszuführenden Ziehvorgang zu ermitteln. Außerdem wird beim DragOver-Ereignis auch die Position in der ListBox bestimmt, für die der Ablegevorgang ausgeführt wird. Wenn die abzulegenden Daten kein String sind, wird DragEventArgs.Effect auf DragDropEffects.None festgelegt. Abschließend wird der Status des Ablegevorgangs im DropLocationLabelLabel angezeigt.

Die in der rechten ListBox abzulegenden Daten werden im DragDrop-Ereignishandler bestimmt. Der String-Wert wird an der entsprechenden Stelle in die ListBox eingefügt. Wenn der Ziehvorgang außerhalb der Grenzen des Formulars beendet wird, wird der Drag & Drop-Vorgang im QueryContinueDrag-Ereignishandler abgebrochen.

In diesem Code wird die Verwendung der QueryContinueDragEventArgs-Klasse mit dem QueryContinueDrag-Ereignis veranschaulicht. Das vollständige Codebeispiel finden Sie unter der DoDragDrop-Methode.

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, System.Windows.Forms.ListBox)

    If Not (lb is 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
private void ListDragSource_QueryContinueDrag(object sender, System.Windows.Forms.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;
        }
    }
}
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, 
    System.Windows.Forms.QueryContinueDragEventArgs e)
{
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = (ListBox)sender;

    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.get_MousePosition().get_X() - screenOffset.get_X() 
            < f.get_DesktopBounds().get_Left() 
            || Control.get_MousePosition().get_X() 
            - screenOffset.get_X() > f.get_DesktopBounds().get_Right() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            < f.get_DesktopBounds().get_Top() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            > f.get_DesktopBounds().get_Bottom()) {
            e.set_Action(DragAction.Cancel);
        }
    }
} //listDragSource_QueryContinueDrag

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

QueryContinueDragEventArgs-Klasse
QueryContinueDragEventArgs-Member
System.Windows.Forms-Namespace
DragAction-Enumeration
DoDragDrop