GiveFeedbackEventHandler 委托

定义

表示处理 ControlGiveFeedback 事件的方法。

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

事件的源。

e
GiveFeedbackEventArgs

包含事件数据的 GiveFeedbackEventArgs

示例

以下示例演示两个 ListBox 控件之间的拖放操作。 该示例在拖动操作启动时调用 DoDragDrop 方法。 如果鼠标在 MouseDown 事件期间从鼠标位置移动了超过 SystemInformation.DragSize,则拖动操作将启动。 IndexFromPoint 方法用于确定在 MouseDown 事件期间要拖动的项的索引。

该示例还演示如何对拖放操作使用自定义游标。 该示例假定两个游标文件(3dwarro.cur3dwno.cur)分别存在于应用程序目录中,分别用于自定义拖放游标。 如果选中 UseCustomCursorsCheckCheckBox,将使用自定义游标。 自定义游标在 GiveFeedback 事件处理程序中设置。

键盘状态在右侧 ListBoxDragOver 事件处理程序中进行评估,以确定拖动操作将基于 SHIFT、Ctrl、Alt 或 Ctrl+Alt 键的状态。 在 DragOver 事件期间,也会确定 ListBox 发生放置的位置。 如果要删除的数据不是 String,则 DragEventArgs.Effect 设置为 DragDropEffects.None。 最后,删除状态显示在 DropLocationLabelLabel中。

要删除的右 ListBox 的数据在 DragDrop 事件处理程序中确定,并在 ListBox的适当位置添加 String 值。 如果拖动操作在窗体边界之外移动,则拖放操作在 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)

获取一个对象,该对象表示由指定委托表示的方法。

适用于

另请参阅