語言

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 方法。 拖曳動作會開始,前提是滑鼠在事件中SystemInformation.DragSize移動MouseDown超過滑鼠位置。 此 IndexFromPoint 方法用於判定事件中 MouseDown 要拖曳項目的索引。

此範例也會示範如何針對拖放作業使用自定義數據指標。 範例假設應用程式目錄中存在兩個游標檔案, 3dwarro.cur3dwno.cur分別用於自訂拖曳游標和無放下游標。 如果 UseCustomCursorsCheckCheckBox 被勾選,就會使用自訂游標。 自訂游標則在事件處理程序中 GiveFeedback 設定。

鍵盤狀態會在事件處理器DragOver中ListBox評估右側 ,根據 SHIFT、CTRL、ALT 或 CTRL+ALT 鍵的狀態來決定拖曳操作。 ListBox掉落地點也會在事件中DragOver決定。 若要丟棄的資料不是 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

適用於