DragAction 列挙体とは? わかりやすく解説

DragAction 列挙体

ドラッグ アンド ドロップ操作継続するかどうか、および継続する場合どのように継続するかを指定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Enumeration DragAction
[ComVisibleAttribute(true)] 
public enum DragAction
[ComVisibleAttribute(true)] 
public enum class DragAction
/** @attribute ComVisibleAttribute(true) */ 
public enum DragAction
ComVisibleAttribute(true) 
public enum DragAction
メンバメンバ
解説解説

この列挙体は、QueryContinueDragEventArgs で使用されます。

使用例使用例

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

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

キーボードの状態は、右側ListBox の DragOver イベント ハンドラ評価されます。ドラッグ操作内容は、Shift キーCtrl キーAlt キー、または Ctrl + Alt キーの状態によって決まりますドロップ発生する ListBox 内の位置は、DragOver イベント時に判定されます。ドロップするデータStringない場合は、DragEventArgs.Effect が DragDropEffects.None に設定されます。最後にドロップステータスDropLocationLabelLabel表示されます。

右側ListBoxドロップするデータは、DragDrop イベント ハンドラ判定されます。また、String 値が ListBox該当する場所に追加されます。ドラッグ操作フォーム範囲超えて移動した場合ドラッグ アンド ドロップ操作は QueryContinueDrag イベント ハンドラキャンセルされます。

DragAction 列挙体の使い方次のコード例示しますコード例全体については、DoDragDrop メソッドトピック参照してください

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, System.Windows.Forms.ListBox)

    If Not (lb is 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
private void ListDragSource_QueryContinueDrag(object
 sender, System.Windows.Forms.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;
        }
    }
}
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, 
    System.Windows.Forms.QueryContinueDragEventArgs e)
{
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = (ListBox)sender;

    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.get_MousePosition().get_X() - screenOffset.get_X()
 
            < f.get_DesktopBounds().get_Left() 
            || Control.get_MousePosition().get_X() 
            - screenOffset.get_X() > f.get_DesktopBounds().get_Right() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            < f.get_DesktopBounds().get_Top() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            > f.get_DesktopBounds().get_Bottom()) {
            e.set_Action(DragAction.Cancel);
        }
    }
} //listDragSource_QueryContinueDrag
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からDragAction 列挙体を検索した結果を表示しています。
Weblioに収録されているすべての辞書からDragAction 列挙体を検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDragAction 列挙体を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DragAction 列挙体」の関連用語

DragAction 列挙体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DragAction 列挙体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS