Control.GiveFeedback Control.GiveFeedback Control.GiveFeedback Control.GiveFeedback Event

定义

在执行拖动操作期间发生。Occurs during a drag operation.

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控件之间的拖放操作。The following code example demonstrates a drag-and-drop operation between two ListBox controls. 该示例在拖动DoDragDrop操作开始时调用方法。The example calls the DoDragDrop method when the drag action starts. 如果在SystemInformation.DragSize MouseDown事件过程中鼠标移动了多个鼠标位置,则拖动操作将启动。The drag action starts if the mouse has moved more than SystemInformation.DragSize from the mouse location during the MouseDown event. 方法用于确定MouseDown事件期间要拖动的项的索引。 IndexFromPointThe IndexFromPoint method is used to determine the index of the item to drag during the MouseDown event.

该示例还演示了如何对拖放操作使用自定义光标。The example also demonstrates using custom cursors for the drag-and-drop operation. 该示例要求在应用程序目录中3dwarro.cur分别3dwno.cur为自定义的拖放和非删除游标提供两个游标文件。The example requires that two cursor files, 3dwarro.cur and 3dwno.cur, exist in the application directory, for the custom drag and no-drop cursors, respectively. UseCustomCursorsCheck 如果CheckBox选中,则将使用自定义光标。The custom cursors will be used if the UseCustomCursorsCheckCheckBox is checked. 自定义游标是在GiveFeedback事件处理程序中设置的。The custom cursors are set in the GiveFeedback event handler.

键盘状态在右侧DragOver ListBox的事件处理程序中进行计算,以根据 SHIFT、ctrl、ALT 或 ctrl + ALT 键确定拖动操作的状态。The keyboard state is evaluated in the DragOver event handler for the right ListBox, to determine what the drag operation will be based on state of the SHIFT, CTRL, ALT, or CTRL+ALT keys. ListBox 事件DragOver期间也会确定放置过程中的位置。The location in the ListBox where the drop would occur is also determined during the DragOver event. 如果要删除String的数据不是, DragEventArgs.Effect则在中DragDropEffects将设置为NoneIf the data to drop is not a String, then the DragEventArgs.Effect is set to None in DragDropEffects. 最后,放置的状态显示在中DropLocationLabelLabelFinally, the status of the drop is displayed in the DropLocationLabelLabel.

ListBox放置给权限的数据DragDrop在事件处理程序中确定,并String将值添加到中ListBox的适当位置。The data to drop for the right ListBox is determined in the DragDrop event handler and the String value is added at the appropriate place in the ListBox. 如果拖动操作移到窗体的边界之外,则会在QueryContinueDrag事件处理程序中取消拖放操作。If the drag operation moves outside the bounds of the form, then the drag-and-drop operation is canceled in the QueryContinueDrag event handler.

此代码摘录演示了如何GiveFeedback使用事件。This code excerpt demonstrates using the GiveFeedback event. 有关完整的代码示例,请参阅方法。DoDragDropSee the DoDragDrop method for the complete code example.

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, 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 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启动拖放操作时,将引发事件。The GiveFeedback event is raised when a drag-and-drop operation is started. 发生此GiveFeedback事件时,拖动事件源可以修改鼠标指针的外观,以便在拖放操作过程中为用户提供视觉反馈。With the GiveFeedback event, the source of a drag event can modify the appearance of the mouse pointer in order to give the user visual feedback during a drag-and-drop operation.

下面描述与拖放操作相关的事件的引发方式以及引发时间。The following describes how and when events related to drag-and-drop operations are raised.

DoDragDrop方法确定当前光标位置下的控件。The DoDragDrop method determines the control under the current cursor location. 然后,它会检查控件是否为有效的拖放目标。It then checks to see if the control is a valid drop target.

如果控件是有效的拖放目标, GiveFeedback则会随指定的拖放效果引发事件。If the control is a valid drop target, the GiveFeedback event is raised with the drag-and-drop effect specified. 有关拖放效果的列表,请参见 DragDropEffects 枚举。For a list of drag-and-drop effects, see the DragDropEffects enumeration.

跟踪鼠标光标位置、键盘状态和鼠标按钮状态的更改。Changes in the mouse cursor position, keyboard state, and mouse button state are tracked.

  • 如果用户移出一个窗口,则引发 DragLeave 事件。If the user moves out of a window, the DragLeave event is raised.

  • 如果鼠标进入另一个控件,则引发该控件的 DragEnterIf the mouse enters another control, the DragEnter for that control is raised.

  • 如果鼠标移动但停留在同一个控件中,则引发 DragOver 事件。If the mouse moves but stays within the same control, the DragOver event is raised.

如果键盘或鼠标按钮状态发生了更改, QueryContinueDrag则会引发事件,并确定是继续拖动、删除数据还是根据事件的Action QueryContinueDragEventArgs属性的值来取消操作。If there is a change in the keyboard or mouse button state, the QueryContinueDrag event is raised and determines whether to continue the drag, to drop the data, or to cancel the operation based on the value of the Action property of the event's QueryContinueDragEventArgs.

  • 如果的DragAction值为ContinueDragOver则会引发事件以继续操作,并且GiveFeedback事件将以新效果引发,以便可以设置适当的视觉反馈。If the value of DragAction is Continue, the DragOver event is raised to continue the operation and the GiveFeedback event is raised with the new effect so appropriate visual feedback can be set. 有关有效放置效果的列表,请参见 DragDropEffects 枚举。For a list of valid drop effects, see the DragDropEffects enumeration.

    备注

    DragOverGiveFeedback事件成对出现,因此,当鼠标移动到拖放目标上时,将为用户提供有关鼠标位置的最新反馈。The DragOver and GiveFeedback events are paired so that as the mouse moves across the drop target, the user is given the most up-to-date feedback on the mouse's position.

  • 如果的DragAction值为Drop,则放置效果值将返回到源,以便源应用程序可以对源数据执行适当的操作; 例如,如果是移动操作,则剪切数据。If the value of DragAction is Drop, the drop effect value is returned to the source, so the source application can perform the appropriate operation on the source data; for example, cut the data if the operation was a move.

  • 如果的DragAction值为CancelDragLeave则引发事件。If the value of DragAction is Cancel, the DragLeave event is raised.

有关处理事件的详细信息, 请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

适用于

另请参阅