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

ドロップを伴って操作が停止されます。

次の例では、2 つの ListBox コントロール間のドラッグ アンド ドロップ操作を示します。 この例では、ドラッグ アクションの DoDragDrop 開始時に メソッドを呼び出します。 ドラッグ 操作は、イベント中にマウスの位置からマウスが移動 SystemInformation.DragSize した場合に MouseDown 開始されます。 メソッドは IndexFromPoint 、イベント中にドラッグする項目のインデックスを MouseDown 決定するために使用されます。

この例では、ドラッグ アンド ドロップ操作にカスタム カーソルを使用する方法も示します。 この例では、 3dwarro.cur カスタム ドラッグ カーソルと 3dwno.curドロップなしカーソルのそれぞれについて、アプリケーション ディレクトリに 2 つのカーソル ファイル と が存在することを前提としています。 がオンになっている場合 UseCustomCursorsCheckCheckBox は、カスタム カーソルが使用されます。 カスタム カーソルは、イベント ハンドラーで GiveFeedback 設定されます。

キーボードの状態は、右 ListBoxのイベント ハンドラーでDragOver評価され、Shift キー、Ctrl キー、Alt キー、または Ctrl + Alt キーの状態に基づいてドラッグ操作が決定されます。 ドロップが発生する内の ListBox 場所も、イベント中に DragOver 決定されます。 削除するデータが でないStringDragEventArgs.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使用されます。

適用対象