DragAction Výčet

Definice

Určuje, jak a jestli má operace přetažení pokračovat.

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
Dědičnost
DragAction
Atributy

Pole

Cancel 2

Operace je zrušena bez zprávy o přetažení.

Continue 0

Operace bude pokračovat.

Drop 1

Operace se zastaví s poklesem.

Příklady

Následující příklad ukazuje operaci přetažení mezi dvěma ListBox ovládacími prvky. Příklad volá metodu DoDragDrop při spuštění akce přetažení. Akce přetažení se spustí, pokud se myš během MouseDown události přesunula více než SystemInformation.DragSize z umístění myši. Metoda IndexFromPoint se používá k určení indexu položky, která se má během MouseDown události přetáhnout.

Příklad také ukazuje použití vlastních kurzorů pro operaci přetažení. V příkladu se předpokládá, 3dwarro.cur že v adresáři aplikace existují dva soubory kurzoru a 3dwno.cur, pro vlastní kurzory přetahování a bez přetažení. Vlastní kurzory se použijí, pokud je zaškrtnuté UseCustomCursorsCheckCheckBox políčko . Vlastní kurzory jsou nastaveny v obslužné rutině GiveFeedback události.

Stav klávesnice se vyhodnocuje v DragOver obslužné rutině události pro pravou ListBox, aby bylo možné určit, jaká operace přetažení bude na základě stavu kláves SHIFT, CTRL, ALT nebo CTRL+ALT. Během události se určí také umístění v ListBox místě, kde by k poklesu DragOver došlo. Pokud data, která se mají vypustit, nejsou String, je DragEventArgs.Effect vlastnost nastavená na DragDropEffects.None. Nakonec se stav přetažení zobrazí v DropLocationLabelLabel.

Data, která se mají vpravo vynechat ListBox , se určí v obslužné rutině DragDrop události a String hodnota se přidá na příslušném místě v ListBox. Pokud se operace přetažení přesune mimo hranice formuláře, operace přetažení se v obslužné rutině QueryContinueDrag události zruší.

Tento výňatek kódu ukazuje použití výčtu DragAction . Kompletní příklad kódu najdete v DoDragDrop metodě .

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

Poznámky

Tento výčet používá .QueryContinueDragEventArgs

Platí pro