GiveFeedbackEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示处理 Control 的 GiveFeedback 事件的方法。
public delegate void GiveFeedbackEventHandler(System::Object ^ sender, GiveFeedbackEventArgs ^ e);
public delegate void GiveFeedbackEventHandler(object sender, GiveFeedbackEventArgs e);
public delegate void GiveFeedbackEventHandler(object? sender, GiveFeedbackEventArgs e);
type GiveFeedbackEventHandler = delegate of obj * GiveFeedbackEventArgs -> unit
Public Delegate Sub GiveFeedbackEventHandler(sender As Object, e As GiveFeedbackEventArgs)
参数
- sender
- Object
事件源。
包含事件数据的 GiveFeedbackEventArgs。
示例
以下示例演示两 ListBox 个控件之间的拖放操作。 该示例在 DoDragDrop 拖动操作启动时调用 方法。 如果鼠标在事件期间MouseDown从鼠标位置移动了超过SystemInformation.DragSize,则开始拖动操作。 方法 IndexFromPoint 用于确定在事件期间要拖动的项的 MouseDown
索引。
该示例还演示如何使用自定义光标进行拖放操作。 该示例假定应用程序目录中存在两个游标文件 3dwarro.cur
和 3dwno.cur
,分别用于自定义拖放游标和不放置游标。 如果选中 , UseCustomCursorsCheck
CheckBox 将使用自定义游标。 自定义游标在 事件处理程序中 GiveFeedback 设置。
键盘状态在右侧 ListBox
的事件处理程序中DragOver计算,以确定拖动操作将基于 SHIFT、CTRL、ALT 或 Ctrl+Alt 键的状态。 在 事件期间DragOver
,ListBox
还会确定发生下降的位置。 如果要删除的数据不是 , String
则将 DragEventArgs.Effect 设置为 DragDropEffects.None。 最后,删除的状态显示在 中 DropLocationLabel
Label。
要在右侧 ListBox
删除的数据在事件处理程序中 DragDrop 确定, String
并将值添加到 中的 ListBox
适当位置。 如果拖动操作移动到窗体边界之外,则会在事件处理程序中 QueryContinueDrag 取消拖放操作。
此代码摘录演示如何将 GiveFeedbackEventHandler 委托与 事件一起使用 GiveFeedback 。 有关完整的代码示例, DoDragDrop 请参阅 方法。
void ListDragSource_GiveFeedback( Object^ /*sender*/, System::Windows::Forms::GiveFeedbackEventArgs^ e )
{
// Use custom cursors if the check box is checked.
if ( UseCustomCursorsCheck->Checked )
{
// Sets the custom cursor based upon the effect.
e->UseDefaultCursors = false;
if ( (e->Effect & DragDropEffects::Move) == DragDropEffects::Move )
::Cursor::Current = MyNormalCursor;
else
::Cursor::Current = MyNoDropCursor;
}
}
private void ListDragSource_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
// Use custom cursors if the check box is checked.
if (UseCustomCursorsCheck.Checked)
{
// Sets the custom cursor based upon the effect.
e.UseDefaultCursors = false;
if ((e.Effect & DragDropEffects.Move) == DragDropEffects.Move)
Cursor.Current = MyNormalCursor;
else
Cursor.Current = MyNoDropCursor;
}
}
Private Sub ListDragSource_GiveFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles ListDragSource.GiveFeedback
' Use custom cursors if the check box is checked.
If (UseCustomCursorsCheck.Checked) Then
' Set the custom cursor based upon the effect.
e.UseDefaultCursors = False
If ((e.Effect And DragDropEffects.Move) = DragDropEffects.Move) Then
Cursor.Current = MyNormalCursor
Else
Cursor.Current = MyNoDropCursor
End If
End If
End Sub
注解
创建 GiveFeedbackEventHandler 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关使用委托处理事件的详细信息,请参阅 处理和引发事件。
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈