DragAction Wyliczenie

Definicja

Określa, jak i czy operacja przeciągania i upuszczania powinna być kontynuowana.

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
Dziedziczenie
DragAction
Atrybuty

Pola

Cancel 2

Operacja jest anulowana bez komunikatu upuszczania.

Continue 0

Operacja będzie kontynuowana.

Drop 1

Operacja zostanie zatrzymana z upuszczaniem.

Przykłady

W poniższym przykładzie przedstawiono operację przeciągania i upuszczania między dwoma ListBox kontrolkami. Przykład wywołuje metodę DoDragDrop po uruchomieniu akcji przeciągania. Akcja przeciągania rozpoczyna się, jeśli mysz przeniosła się więcej niż SystemInformation.DragSize z lokalizacji myszy podczas MouseDown zdarzenia. Metoda IndexFromPoint służy do określania indeksu elementu do przeciągania podczas MouseDown zdarzenia.

W przykładzie pokazano również użycie niestandardowych kursorów dla operacji przeciągania i upuszczania. W przykładzie założono, 3dwarro.cur że dwa pliki kursora i 3dwno.cur, istnieją w katalogu aplikacji, odpowiednio dla niestandardowego przeciągania i nie upuszczania kursorów. Niestandardowe kursory będą używane, jeśli UseCustomCursorsCheckCheckBox jest zaznaczone. Niestandardowe kursory są ustawiane w procedurze obsługi zdarzeń GiveFeedback .

Stan klawiatury jest oceniany w procedurze DragOver obsługi zdarzeń po prawej stronie ListBox, aby określić, jaka operacja przeciągania będzie oparta na stanie klawiszy SHIFT, CTRL, ALT lub CTRL+ALT. Lokalizacja, w ListBox której wystąpi spadek, jest również określana podczas DragOver zdarzenia. Jeśli dane do upuszczania nie są wartością String, DragEventArgs.Effect parametr jest ustawiony na DragDropEffects.Nonewartość . Na koniec stan upuszczania jest wyświetlany w elemecie DropLocationLabelLabel.

Dane do upuszczania po prawej stronie ListBox są określane w DragDrop procedurze obsługi zdarzeń, a String wartość jest dodawana w odpowiednim miejscu w obiekcie ListBox. Jeśli operacja przeciągania przesuwa się poza granice formularza, operacja przeciągania i upuszczania zostanie anulowana w procedurze obsługi zdarzeń QueryContinueDrag .

Ten fragment kodu pokazuje użycie wyliczenia DragAction . Zobacz metodę DoDragDrop kompletnego przykładu kodu.

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

Uwagi

Ta wyliczenie jest używana przez program QueryContinueDragEventArgs.

Dotyczy