Control.QueryContinueDrag イベント

定義

ドラッグ アンド ドロップ操作中に発生し、ドラッグ ソースがドラッグ アンド ドロップ操作をキャンセルする必要があるかどうかを決定できるようにします。

public:
 event System::Windows::Forms::QueryContinueDragEventHandler ^ QueryContinueDrag;
public event System.Windows.Forms.QueryContinueDragEventHandler QueryContinueDrag;
public event System.Windows.Forms.QueryContinueDragEventHandler? QueryContinueDrag;
member this.QueryContinueDrag : System.Windows.Forms.QueryContinueDragEventHandler 
Public Custom Event QueryContinueDrag As QueryContinueDragEventHandler 

イベントの種類

このコードの抜粋は、ドラッグ操作が QueryContinueDrag フォームの境界外に移動した場合に、 イベントを使用してドラッグ アンド ドロップ操作を取り消す方法を示しています。 完全な 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

注釈

このイベントは QueryContinueDrag 、ドラッグ アンド ドロップ操作中にキーボードまたはマウス ボタンの状態が変更されると発生します。 イベント QueryContinueDrag を使用すると、ドラッグ ソースでドラッグ アンド ドロップ操作を取り消す必要があるかどうかを判断できます。

ドラッグ アンド ドロップ操作関連のイベントがどのように、いつ発生するかについて次に示します。

メソッドは DoDragDrop 、現在のカーソル位置の下のコントロールを決定します。 次に、コントロールが有効なドロップ ターゲットであるかどうかを確認します。

コントロールが有効なドロップ ターゲットの場合、 GiveFeedback ドラッグ アンド ドロップ効果を指定してイベントが発生します。 ドラッグ アンド ドロップ効果の一覧については、DragDropEffects 列挙体を参照してください。

マウス カーソルの位置、キーボードの状態、およびマウス ボタンの状態の変更が監視されます。

  • ユーザーがウィンドウの外に移動した場合、DragLeave イベントが生成されます。

  • マウスが別のコントロールに移動した場合は、そのコントロールの DragEnter が生成されます。

  • マウスが移動しても同じコントロール内の場合は、DragOver イベントが生成されます。

キーボードまたはマウス ボタンの状態が変更された場合、イベントが発生し、QueryContinueDragドラッグを続行するか、データをドロップするか、イベントQueryContinueDragEventArgsの の プロパティの値に基づいて操作をAction取り消すかが決定されます。

  • DragAction 値が Continueの場合、操作を DragOver 続行するためにイベントが発生し、 GiveFeedback 適切な視覚的フィードバックを設定できるように、新しい効果でイベントが発生します。 有効なドロップ効果の一覧については、DragDropEffects 列挙体を参照してください。

    注意

    DragOverイベントと GiveFeedback イベントはペアになっているため、マウスがドロップ ターゲットを移動すると、ユーザーにはマウスの位置に関する最新のフィードバックが表示されます。

  • DragAction 値が Dropの場合、ドロップ効果の値がソースに返されるため、ソース アプリケーションはソース データに対して適切な操作を実行できます。たとえば、操作が移動の場合はデータを切り取ります。

  • の値が のDragActionCancel場合、イベントが発生しますDragLeave

既定では、ESC キーがQueryContinueDrag押された場合、イベントは にDragAction設定CancelActionされ、左、中央、または右のマウス ボタンが押された場合は にDragAction設定ActionDropされます。

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。

適用対象

こちらもご覧ください