Control.GiveFeedback 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在执行拖动操作期间发生。
public:
event System::Windows::Forms::GiveFeedbackEventHandler ^ GiveFeedback;
public event System.Windows.Forms.GiveFeedbackEventHandler GiveFeedback;
public event System.Windows.Forms.GiveFeedbackEventHandler? GiveFeedback;
member this.GiveFeedback : System.Windows.Forms.GiveFeedbackEventHandler
Public Custom Event GiveFeedback As GiveFeedbackEventHandler
事件类型
示例
下面的代码示例演示两 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 取消拖放操作。
此代码摘录演示了如何使用 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
注解
启动 GiveFeedback 拖放操作时引发 事件。 GiveFeedback借助 事件,拖动事件的源可以修改鼠标指针的外观,以便在拖放操作期间为用户提供视觉反馈。
下面描述与拖放操作相关的事件的引发方式以及引发时间。
方法 DoDragDrop 确定当前光标位置下的控件。 然后,它会检查控件是否是有效的放置目标。
如果控件是有效的放置目标,则会 GiveFeedback 使用指定的拖放效果引发 事件。 有关拖放效果的列表,请参见 DragDropEffects 枚举。
跟踪鼠标光标位置、键盘状态和鼠标按钮状态的更改。
如果键盘或鼠标按钮状态发生更改,则会QueryContinueDrag引发 事件,并根据事件的 QueryContinueDragEventArgs的 属性的值Action确定是继续拖动、删除数据还是取消操作。
如果 的DragAction
Continue
值为 ,则会DragOver引发 事件以继续操作,并使用GiveFeedback新效果引发 事件,以便设置适当的视觉反馈。 有关有效放置效果的列表,请参见 DragDropEffects 枚举。注意
DragOver和 GiveFeedback 事件配对,以便当鼠标在放置目标上移动时,用户将获得有关鼠标位置的最新反馈。
如果 的DragAction
Drop
值为 ,则删除效果值将返回到源,因此源应用程序可以对源数据执行相应的操作;例如,如果操作是移动,则剪切数据。如果 的DragAction
Cancel
值为 ,则DragLeave引发 事件。
有关处理事件的详细信息,请参阅 处理和引发事件。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈