Bagikan melalui


Control.QueryContinueDrag Kejadian

Definisi

Terjadi selama operasi seret dan letakkan dan memungkinkan sumber seret untuk menentukan apakah operasi seret dan letakkan harus dibatalkan.

public:
 event System::Windows::Forms::QueryContinueDragEventHandler ^ QueryContinueDrag;
public event System.Windows.Forms.QueryContinueDragEventHandler QueryContinueDrag;
public event System.Windows.Forms.QueryContinueDragEventHandler? QueryContinueDrag;
member this.QueryContinueDrag : System.Windows.Forms.QueryContinueDragEventHandler 
Public Custom Event QueryContinueDrag As QueryContinueDragEventHandler 

Jenis Acara

Contoh

Kutipan kode ini menunjukkan penggunaan QueryContinueDrag peristiwa untuk membatalkan operasi seret dan letakkan jika operasi seret bergerak di luar batas formulir. 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

Peristiwa QueryContinueDrag dinaikkan ketika ada perubahan dalam status tombol keyboard atau mouse selama operasi seret dan letakkan. Kejadian ini QueryContinueDrag memungkinkan sumber seret untuk menentukan apakah operasi seret dan letakkan harus dibatalkan.

Berikut ini menjelaskan bagaimana dan kapan peristiwa yang terkait dengan operasi seret dan letakkan dinaikkan.

Metode DoDragDrop menentukan kontrol di bawah lokasi kursor saat ini. Kemudian memeriksa untuk melihat apakah kontrol adalah target penurunan yang valid.

Jika kontrol adalah target drop yang valid, GiveFeedback peristiwa akan dinaikkan dengan efek seret dan letakkan yang ditentukan. Untuk daftar efek seret dan letakkan, lihat DragDropEffects enumerasi.

Perubahan pada posisi kursor mouse, status keyboard, dan status tombol mouse dilacak.

  • Jika pengguna berpindah dari jendela, DragLeave peristiwa akan dinaikkan.

  • Jika mouse memasuki kontrol lain, untuk kontrol tersebut DragEnter akan dinaikkan.

  • Jika mouse bergerak tetapi tetap berada dalam kontrol yang sama, DragOver peristiwa akan dinaikkan.

Jika ada perubahan dalam status tombol keyboard atau mouse, QueryContinueDrag peristiwa dinaikkan dan menentukan apakah akan melanjutkan seret, untuk menghilangkan data, atau membatalkan operasi berdasarkan nilai Action properti peristiwa QueryContinueDragEventArgs.

  • Jika nilainya DragAction adalah Continue, DragOver peristiwa dinaikkan untuk melanjutkan operasi dan GiveFeedback peristiwa dinaikkan dengan efek baru sehingga umpan balik visual yang sesuai dapat diatur. Untuk daftar efek penurunan yang valid, lihat DragDropEffects enumerasi.

    Nota

    Peristiwa DragOver dan GiveFeedback dipasangkan sehingga saat mouse bergerak melintasi target drop, pengguna diberi umpan balik -tanggal yang paling up-topada posisi mouse.

  • Jika nilai DragAction adalah Drop, nilai efek penurunan dikembalikan ke sumber, sehingga aplikasi sumber dapat melakukan operasi yang sesuai pada data sumber; misalnya, memotong data jika operasi adalah pemindahan.

  • Jika nilainya DragAction adalah Cancel, DragLeave peristiwa akan dinaikkan.

Secara default, QueryContinueDrag peristiwa diatur Action ke Cancel jika DragAction tombol ESC ditekan dan diatur Action ke Drop jika DragAction tombol kiri, tengah, atau kanan mouse ditekan.

Untuk informasi selengkapnya tentang menangani peristiwa, lihat Menangani dan Meningkatkan Peristiwa.

Berlaku untuk

Lihat juga