GiveFeedbackEventArgs.Effect 属性

定义

获取显示的拖放操作反馈。

public:
 property System::Windows::Forms::DragDropEffects Effect { System::Windows::Forms::DragDropEffects get(); };
public System.Windows.Forms.DragDropEffects Effect { get; }
member this.Effect : System.Windows.Forms.DragDropEffects
Public ReadOnly Property Effect As DragDropEffects

属性值

DragDropEffects 值之一。

示例

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

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

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

要在右侧 ListBox 删除的数据在事件处理程序中 DragDrop 确定, String 值将添加到 中的 ListBox相应位置。 如果拖动操作移动到窗体边界之外,则会在事件处理程序中 QueryContinueDrag 取消拖放操作。

此代码摘录演示如何使用 GiveFeedbackEventArgs 类。 有关完整代码示例, 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

适用于