Sdílet prostřednictvím


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 se zruší bez rozevírací zprávy.

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 během události MouseDown přesunulo více než SystemInformation.DragSize z umístění myši. Metoda IndexFromPoint slouží k určení indexu položky, která se má přetáhnout během události MouseDown.

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

Stav klávesnice se vyhodnocuje v obslužné rutině události DragOver pro správnou ListBox, aby bylo možné určit, jaké operace přetažení bude založená na stavu kláves SHIFT, CTRL, ALT nebo CTRL+ALT. Umístění v ListBox, kde dojde k poklesu, je také určeno během DragOver události. Pokud data, která chcete vypustit, nejsou String, je DragEventArgs.Effect nastavena na DragDropEffects.None. Nakonec se stav poklesu zobrazí v DropLocationLabelLabel.

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

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

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