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 鍵的狀態來判斷拖曳作業將是什麼。 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

適用於