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 鍵的狀態來判斷拖曳作業會是什麼。 ListBox
在 事件發生期間 DragOver
也會決定卸載的位置。 如果要卸載的資料不是 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 列舉型別。
系統會追蹤滑鼠游標位置、鍵盤狀態和滑鼠按鈕狀態的變更。
如果使用者移出視窗外,便會引發 DragLeave 事件。
如果滑鼠進入另一個控制項,便會引發該控制項的 DragEnter 事件。
如果滑鼠移動,但是待在相同的控制項內,便會引發 DragOver 事件。
如果鍵盤或滑鼠按鍵狀態有所變更,就會 QueryContinueDrag 引發事件,並判斷是否要繼續拖曳、卸載資料,或根據 Action 事件的 QueryContinueDragEventArgs 屬性值取消作業。
如果 的值 DragAction 是 ,則會 DragOver 引發 事件以繼續作業,並且 GiveFeedback 以新的效果引發事件,因此可以設定
Continue
適當的視覺回饋。 如需有效置放效果的清單,請參閱 DragDropEffects 列舉型別。注意
和 DragOverGiveFeedback 事件會配對,如此一來,當滑鼠在置放目標之間移動時,使用者就會獲得滑鼠位置的最新意見反應。
如果 的值 DragAction 是
Drop
,則卸載效果值會傳回至來源,因此來源應用程式可以在來源資料上執行適當的作業;例如,如果作業是移動,請剪下資料。如果 的值 DragAction 是
Cancel
,就會 DragLeave 引發 事件。
如需處理事件的詳細資訊,請參閱 處理和引發事件。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應