QueryContinueDragEventHandler 代理人

定義

代表將處理 QueryContinueDragControl 事件的方法。

public delegate void QueryContinueDragEventHandler(System::Object ^ sender, QueryContinueDragEventArgs ^ e);
public delegate void QueryContinueDragEventHandler(object sender, QueryContinueDragEventArgs e);
public delegate void QueryContinueDragEventHandler(object? sender, QueryContinueDragEventArgs e);
type QueryContinueDragEventHandler = delegate of obj * QueryContinueDragEventArgs -> unit
Public Delegate Sub QueryContinueDragEventHandler(sender As Object, e As QueryContinueDragEventArgs)

參數

sender
Object

事件的來源。

e
QueryContinueDragEventArgs

QueryContinueDragEventArgs,其中包含事件資料。

範例

下列範例示範兩 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 取消拖放作業。

此程式碼摘錄示範搭配 事件使用 QueryContinueDragEventHandler 委派 QueryContinueDragDoDragDrop如需完整的程式碼範例,請參閱 方法。

void ListDragSource_QueryContinueDrag( Object^ sender, System::Windows::Forms::QueryContinueDragEventArgs^ e )
{
   // Cancel the drag if the mouse moves off the form.
   ListBox^ lb = dynamic_cast<ListBox^>(sender);
   if ( lb != nullptr )
   {
      Form^ f = lb->FindForm();

      // Cancel the drag if the mouse moves off the form. The screenOffset
      // takes into account any desktop bands that may be at the top or left
      // side of the screen.
      if ( ((Control::MousePosition.X - screenOffset.X) < f->DesktopBounds.Left) || ((Control::MousePosition.X - screenOffset.X) > f->DesktopBounds.Right) || ((Control::MousePosition.Y - screenOffset.Y) < f->DesktopBounds.Top) || ((Control::MousePosition.Y - screenOffset.Y) > f->DesktopBounds.Bottom) )
      {
         e->Action = DragAction::Cancel;
      }
   }
}
private void ListDragSource_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = sender as ListBox;

    if (lb != null)
    {
        Form f = lb.FindForm();

        // Cancel the drag if the mouse moves off the form. The screenOffset
        // takes into account any desktop bands that may be at the top or left
        // side of the screen.
        if (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) ||
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) ||
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) ||
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom))
        {
            e.Action = DragAction.Cancel;
        }
    }
}
Private Sub ListDragSource_QueryContinueDrag(ByVal sender As Object, ByVal e As QueryContinueDragEventArgs) Handles ListDragSource.QueryContinueDrag
    ' Cancel the drag if the mouse moves off the form.
    Dim lb As ListBox = CType(sender, ListBox)

    If (lb IsNot Nothing) Then

        Dim f As Form = lb.FindForm()

        ' Cancel the drag if the mouse moves off the form. The screenOffset
        ' takes into account any desktop bands that may be at the top or left
        ' side of the screen.
        If (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) Or
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) Or
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) Or
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) Then

            e.Action = DragAction.Cancel
        End If
    End If
End Sub

備註

建立 QueryContinueDragEventHandler 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需使用委派處理事件的詳細資訊,請參閱 處理和引發事件

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱