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. Наконец, состояние удаления отображается в 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.

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