Поделиться через


DragAction Перечисление

Определение

Указывает, как и если операция перетаскивания должна продолжаться.

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
Наследование
DragAction
Атрибуты

Поля

Cancel 2

Операция отменяется без сообщения об удалении.

Continue 0

Операция продолжится.

Drop 1

Операция остановится с удалением.

Примеры

В следующем примере демонстрируется операция перетаскивания между двумя элементами управления ListBox. В примере вызывается метод DoDragDrop при запуске действия перетаскивания. Действие перетаскивания начинается, если мышь перемещает больше SystemInformation.DragSize из расположения мыши во время события MouseDown. Метод IndexFromPoint используется для определения индекса элемента для перетаскивания во время события MouseDown.

В примере также показано использование пользовательских курсоров для операции перетаскивания. В примере предполагается, что два файла курсора, 3dwarro.cur и 3dwno.cur, существуют в каталоге приложения для настраиваемых курсоров перетаскивания и без перетаскивания соответственно. Пользовательские курсоры будут использоваться при проверке UseCustomCursorsCheckCheckBox. Пользовательские курсоры задаются в обработчике событий GiveFeedback.

Состояние клавиатуры вычисляется в обработчике событий DragOver для правой ListBox, чтобы определить, какая операция перетаскивания будет основываться на состоянии клавиш SHIFT, CTRL, ALT или CTRL+ALT. Расположение в ListBox, где будет происходить удаление, также определяется во время события DragOver. Если данные для удаления не являются String, то DragEventArgs.Effect для DragDropEffects.Noneзадано значение DragDropEffects.None. Наконец, состояние удаления отображается в DropLocationLabelLabel.

Данные, которые нужно удалить для правой ListBox, определяются в обработчике событий DragDrop, а значение String добавляется в соответствующее место в ListBox. Если операция перетаскивания перемещается за пределы формы, операция перетаскивания отменяется в обработчике событий QueryContinueDrag.

Этот фрагмент кода демонстрирует использование перечисления DragAction. См. метод 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

Комментарии

Это перечисление используется QueryContinueDragEventArgs.

Применяется к