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
Атрибуты

Поля

Имя Значение Описание
Continue 0

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

Drop 1

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

Cancel 2

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

Примеры

В следующем примере демонстрируется операция перетаскивания между двумя 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значение . Наконец, в списке 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.

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