QueryContinueDragEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示将用来处理 QueryContinueDrag 的 Control 事件的方法。
public delegate void QueryContinueDragEventHandler(System::Object ^ sender, QueryContinueDragEventArgs ^ e);
public delegate void QueryContinueDragEventHandler(object sender, QueryContinueDragEventArgs e);
public delegate void QueryContinueDragEventHandler(object? sender, QueryContinueDragEventArgs e);
type QueryContinueDragEventHandler = delegate of obj * QueryContinueDragEventArgs -> unit
Public Delegate Sub QueryContinueDragEventHandler(sender As Object, e As QueryContinueDragEventArgs)
参数
- sender
- Object
事件源。
示例
以下示例演示两 ListBox 个控件之间的拖放操作。 该示例在拖动操作启动时调用 DoDragDrop 该方法。 如果鼠标在事件期间MouseDown已从鼠标位置移动超过SystemInformation.DragSize鼠标位置,则拖动操作将开始。 该方法 IndexFromPoint 用于确定在事件期间 MouseDown 要拖动的项的索引。
该示例还演示了如何对拖放操作使用自定义游标。 该示例假定应用程序目录中分别存在两个游标文件 3dwarro.cur 3dwno.cur以及自定义拖放游标。 如果UseCustomCursorsCheckCheckBox选中自定义游标,将使用自定义游标。 自定义游标在事件处理程序中 GiveFeedback 设置。
键盘状态在右侧ListBox的事件处理程序中DragOver评估,以确定拖动操作将基于 SHIFT、Ctrl、Alt 或 Ctrl+Alt 键的状态。 ListBox在事件发生期间DragOver也会确定放置位置。 If the data to drop is not a String, then the DragEventArgs.Effect is set to DragDropEffects.None. 最后,下拉列表的状态显示在 .DropLocationLabel Label
要删除右侧 ListBox 的数据在事件处理程序中 DragDrop 确定,并在 String 相应位置 ListBox添加值。 如果拖动操作在窗体边界外移动,则会在 QueryContinueDrag 事件处理程序中取消拖放操作。
此代码摘录演示了将 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
注解
创建 QueryContinueDragEventHandler 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关使用委托处理事件的详细信息,请参阅 处理和引发事件。
扩展方法
| GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |