QueryContinueDragEventHandler Delegasikan

Definisi

Mewakili metode yang akan menangani QueryContinueDrag peristiwa Control.

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)

Parameter

sender
Object

Sumber peristiwa.

Contoh

Contoh berikut menunjukkan operasi seret dan letakkan di antara dua ListBox kontrol. Contoh memanggil DoDragDrop metode saat tindakan seret dimulai. Tindakan seret dimulai jika mouse telah memindahkan lebih dari SystemInformation.DragSize dari lokasi mouse selama MouseDown peristiwa. Metode IndexFromPoint ini digunakan untuk menentukan indeks item yang akan diseret selama MouseDown peristiwa.

Contoh ini juga menunjukkan penggunaan kursor kustom untuk operasi seret dan letakkan. Contoh mengasumsikan bahwa dua file kursor, 3dwarro.cur dan 3dwno.cur, ada di direktori aplikasi, untuk kursor seret dan tanpa jatuhkan kustom. Kursor kustom akan digunakan jika UseCustomCursorsCheckCheckBox dicentang. Kursor kustom diatur dalam penanganan GiveFeedback aktivitas.

Status keyboard dievaluasi di DragOver penanganan aktivitas untuk sebelah kanan ListBox, untuk menentukan operasi seret berdasarkan status tombol SHIFT, CTRL, ALT, atau CTRL+ALT. Lokasi di ListBox mana penurunan akan terjadi juga ditentukan selama peristiwa.DragOver Jika data yang akan dihilangkan bukan String, maka DragEventArgs.Effect diatur ke DragDropEffects.None. Akhirnya, status penurunan ditampilkan di DropLocationLabelLabel.

Data yang akan dihilangkan untuk hak ListBox ditentukan dalam DragDrop penanganan aktivitas dan String nilai ditambahkan di tempat yang sesuai di ListBox. Jika operasi seret bergerak di luar batas formulir, maka operasi seret dan letakkan dibatalkan di QueryContinueDrag penanganan aktivitas.

Kutipan kode ini menunjukkan penggunaan QueryContinueDragEventHandler delegasi dengan peristiwa tersebut QueryContinueDrag . DoDragDrop Lihat metode untuk contoh kode lengkap.

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

Keterangan

Saat membuat QueryContinueDragEventHandler delegasi, Anda mengidentifikasi metode yang akan menangani peristiwa. Untuk mengaitkan peristiwa dengan penanganan aktivitas Anda, tambahkan instans delegasi ke peristiwa. Penanganan aktivitas dipanggil setiap kali peristiwa terjadi, kecuali Jika Anda menghapus delegasi. Untuk informasi selengkapnya tentang menangani peristiwa dengan delegasi, lihat Menangani dan Meningkatkan Peristiwa.

Metode Ekstensi

GetMethodInfo(Delegate)

Mendapatkan objek yang mewakili metode yang diwakili oleh delegasi yang ditentukan.

Berlaku untuk

Lihat juga