DragAction Enum

Definisi

Menentukan bagaimana dan apakah operasi seret dan letakkan harus dilanjutkan.

public enum class DragAction
[System.Runtime.InteropServices.ComVisible(true)]
public enum DragAction
public enum DragAction
[<System.Runtime.InteropServices.ComVisible(true)>]
type DragAction = 
type DragAction = 
Public Enum DragAction
Warisan
DragAction
Atribut

Bidang

Cancel 2

Operasi dibatalkan tanpa pesan jatuh.

Continue 0

Operasi akan dilanjutkan.

Drop 1

Operasi akan berhenti dengan penurunan.

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. Contohnya mengasumsikan bahwa dua file kursor, 3dwarro.cur dan 3dwno.cur, ada di direktori aplikasi, untuk kursor seret dan tanpa letakkan kustom. Kursor kustom akan digunakan jika UseCustomCursorsCheckCheckBox dicentang. Kursor kustom diatur dalam penanganan GiveFeedback aktivitas.

Status keyboard dievaluasi dalam DragOver penanganan aktivitas untuk di 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 DragOver peristiwa. 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 penanganan QueryContinueDrag aktivitas.

Kutipan kode ini menunjukkan menggunakan DragAction enumerasi. 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

Enumerasi ini digunakan oleh QueryContinueDragEventArgs.

Berlaku untuk