ToolStripItem.DragEnter イベント
メモ : このイベントは、.NET Framework version 2.0 で新しく追加されたものです。
この項目のクライアント領域に対し、ユーザーが項目をドラッグしたときに発生します。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
Dim instance As ToolStripItem Dim handler As DragEventHandler AddHandler instance.DragEnter, handler
public: event DragEventHandler^ DragEnter { void add (DragEventHandler^ value); void remove (DragEventHandler^ value); }

DragEnter イベントは、ユーザーがドラッグ アンド ドロップ操作中、最初にマウス カーソルを項目上にドラッグすると発生します。
ドラッグ アンド ドロップ操作関連のイベントがどのように、いつ発生するかについて次に示します。
DoDragDrop メソッドは、現在のカーソル位置のアイテムを判別します。次に、アイテムが有効なドロップ ターゲットかどうかを確認します。
項目が有効なドロップ ターゲットの場合、指定したドラッグ アンド ドロップの効果が付いた状態で GiveFeedback イベントが発生します。ドラッグ アンド ドロップ効果の一覧については、DragDropEffects 列挙体を参照してください。
マウス カーソルの位置、キーボードの状態、およびマウス ボタンの状態の変更は、次の方法で監視されます。
キーボードまたはマウス ボタンの状態に変更があった場合、QueryContinueDrag イベントが生成され、このイベントの QueryContinueDragEventArgs の Action プロパティの値に応じて、ドラッグを継続するか、データをドロップするか、操作をキャンセルするかが判断されます。
DragAction の値が Continue の場合、操作を継続するための DragOver イベントが生成され、適切な視覚的フィードバックを設定できるように新しい効果による GiveFeedback イベントが生成されます。有効なドロップ効果の一覧については、DragDropEffects 列挙体を参照してください。
DragOver イベントおよび GiveFeedback イベントはペアになっています。したがって、次のように、マウスがドロップ ターゲットをまたがって移動した場合、マウスの位置に関する最新のフィードバックがユーザーに提示されます。
-
DragAction の値が Drop の場合、ドロップ効果の値がソースに返されます。ソース アプリケーションでは、ソース データに対して適切な操作を実行できます。たとえば、移動操作だった場合は、データの切り取りなどを実行できます。
![]() |
---|

X プロパティおよび Y プロパティをクライアントの Point に変換する方法を次のコード例に示します。このコード例は、ToolStripRenderer クラスのトピックで取り上げているコード例の一部分です。
' This method defines the DragOver event behavior. Protected Overrides Sub OnDragOver(dea As DragEventArgs) MyBase.OnDragOver(dea) ' Get the ToolStripButton control ' at the given mouse position. Dim p As New Point(dea.X, dea.Y) Dim item As ToolStripButton = CType(Me.GetItemAt(Me.PointToClient(p)), ToolStripButton) ' If the ToolStripButton control is the empty cell, ' indicate that the move operation is valid. If item Is Me.emptyCellButton Then ' Set the drag operation to indicate a valid move. dea.Effect = DragDropEffects.Move End If End Sub
// This method defines the DragOver event behavior. protected override void OnDragOver(DragEventArgs dea) { base.OnDragOver(dea); // Get the ToolStripButton control // at the given mouse position. Point p = new Point(dea.X, dea.Y); ToolStripButton item = this.GetItemAt( this.PointToClient(p)) as ToolStripButton; // If the ToolStripButton control is the empty cell, // indicate that the move operation is valid. if( item == this.emptyCellButton ) { // Set the drag operation to indicate a valid move. dea.Effect = DragDropEffects.Move; } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ToolStripItem.DragEnter イベントのページへのリンク