次の方法で共有


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 メソッドを呼び出します。 ドラッグ 操作は、MouseDown イベント中にマウスの位置からマウスが SystemInformation.DragSize 以上移動した場合に開始されます。 IndexFromPoint メソッドは、MouseDown イベント中にドラッグする項目のインデックスを決定するために使用されます。

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

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

適用対象