Control.DragOver Olay

Tanım

Bir nesne denetimin sınırları üzerine sürüklendiğinde gerçekleşir.

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

Olay Türü

Örnekler

Aşağıdaki kod örneği, iki ListBox denetim arasındaki sürükle ve bırak işlemini gösterir. Örnek, sürükleme eylemi başlatıldığında yöntemini çağırır DoDragDrop . Fare olay sırasında MouseDown fare konumundan daha fazla SystemInformation.DragSize hareket ettiyse sürükleme eylemi başlatılır. IndexFromPoint yöntemi, olay sırasında sürüklenecek öğenin dizinini MouseDown belirlemek için kullanılır.

Örnekte, sürükle ve bırak işlemi için özel imleçlerin kullanılması da gösterilmektedir. Örnek, 3dwarro.cur özel sürükleme ve bırakmama imleçleri için uygulama dizininde sırasıyla iki imleç dosyası ve 3dwno.curolmasını gerektirir. İşaretlenirse UseCustomCursorsCheckCheckBox özel imleçler kullanılır. Özel imleçler olay işleyicisinde GiveFeedback ayarlanır.

Klavye durumu, shift, CTRL, ALT veya CTRL+ALT tuşlarının durumuna bağlı olarak sürükleme işleminin ne olacağını belirlemek üzere sağ ListBoxiçin olay işleyicisinde değerlendirilirDragOver. Bırakma işleminin ListBox gerçekleşeceği konum da olay sırasında DragOver belirlenir. Bırakacak veriler bir Stringdeğilse, DragEventArgs.Effect içinde olarak NoneDragDropEffectsayarlanır. Son olarak, bırakmanın durumu içinde DropLocationLabelLabelgörüntülenir.

Sağ ListBox için bırakacak veriler olay işleyicisinde DragDrop belirlenir ve String değeri içinde ListBoxuygun yere eklenir. Sürükleme işlemi formun sınırlarının dışına taşınırsa, sürükle ve bırak işlemi olay işleyicisinde QueryContinueDrag iptal edilir.

Bu kod alıntısı, olayı kullanmayı DragOver gösterir. DoDragDrop Tam kod örneği için yöntemine bakın.

void ListDragTarget_DragOver( Object^ /*sender*/, System::Windows::Forms::DragEventArgs^ e )
{
   // Determine whether string data exists in the drop data. If not, then
   // the drop effect reflects that the drop cannot occur.
   if (  !e->Data->GetDataPresent( System::String::typeid ) )
   {
      e->Effect = DragDropEffects::None;
      DropLocationLabel->Text = "None - no string data.";
      return;
   }

   // Set the effect based upon the KeyState.
   if ( (e->KeyState & (8 + 32)) == (8 + 32) && ((e->AllowedEffect & DragDropEffects::Link) == DragDropEffects::Link) )
   {
      // KeyState 8 + 32 = CTRL + ALT
      // Link drag-and-drop effect.
      e->Effect = DragDropEffects::Link;
   }
   else
   if ( (e->KeyState & 32) == 32 && ((e->AllowedEffect & DragDropEffects::Link) == DragDropEffects::Link) )
   {
      // ALT KeyState for link.
      e->Effect = DragDropEffects::Link;
   }
   else
   if ( (e->KeyState & 4) == 4 && ((e->AllowedEffect & DragDropEffects::Move) == DragDropEffects::Move) )
   {
      // SHIFT KeyState for move.
      e->Effect = DragDropEffects::Move;
   }
   else
   if ( (e->KeyState & 8) == 8 && ((e->AllowedEffect & DragDropEffects::Copy) == DragDropEffects::Copy) )
   {
      // CTRL KeyState for copy.
      e->Effect = DragDropEffects::Copy;
   }
   else
   if ( (e->AllowedEffect & DragDropEffects::Move) == DragDropEffects::Move )
   {
      // By default, the drop action should be move, if allowed.
      e->Effect = DragDropEffects::Move;
   }
   else
            e->Effect = DragDropEffects::None;





   
   // Get the index of the item the mouse is below.
   // The mouse locations are relative to the screen, so they must be
   // converted to client coordinates.
   indexOfItemUnderMouseToDrop = ListDragTarget->IndexFromPoint( ListDragTarget->PointToClient( Point(e->X,e->Y) ) );
   
   // Updates the label text.
   if ( indexOfItemUnderMouseToDrop != ListBox::NoMatches )
   {
      DropLocationLabel->Text = String::Concat( "Drops before item # ", (indexOfItemUnderMouseToDrop + 1) );
   }
   else
            DropLocationLabel->Text = "Drops at the end.";
}
private void ListDragTarget_DragOver(object sender, DragEventArgs e)
{
    // Determine whether string data exists in the drop data. If not, then
    // the drop effect reflects that the drop cannot occur.
    if (!e.Data.GetDataPresent(typeof(System.String)))
    {
        e.Effect = DragDropEffects.None;
        DropLocationLabel.Text = "None - no string data.";
        return;
    }

    // Set the effect based upon the KeyState.
    if ((e.KeyState & (8 + 32)) == (8 + 32) &&
        (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
    {
        // KeyState 8 + 32 = CTRL + ALT

        // Link drag-and-drop effect.
        e.Effect = DragDropEffects.Link;
    }
    else if ((e.KeyState & 32) == 32 &&
        (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
    {
        // ALT KeyState for link.
        e.Effect = DragDropEffects.Link;
    }
    else if ((e.KeyState & 4) == 4 &&
        (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
    {
        // SHIFT KeyState for move.
        e.Effect = DragDropEffects.Move;
    }
    else if ((e.KeyState & 8) == 8 &&
        (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
    {
        // CTRL KeyState for copy.
        e.Effect = DragDropEffects.Copy;
    }
    else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
    {
        // By default, the drop action should be move, if allowed.
        e.Effect = DragDropEffects.Move;
    }
    else
    {
        e.Effect = DragDropEffects.None;
    }

    // Get the index of the item the mouse is below. 

    // The mouse locations are relative to the screen, so they must be 
    // converted to client coordinates.

    indexOfItemUnderMouseToDrop =
        ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(new Point(e.X, e.Y)));

    // Updates the label text.
    if (indexOfItemUnderMouseToDrop != ListBox.NoMatches)
    {
        DropLocationLabel.Text = "Drops before item #" + (indexOfItemUnderMouseToDrop + 1);
    }
    else
    {
        DropLocationLabel.Text = "Drops at the end.";
    }
}
Private Sub ListDragTarget_DragOver(ByVal sender As Object, ByVal e As DragEventArgs) Handles ListDragTarget.DragOver
    ' Determine whether string data exists in the drop data. If not, then
    ' the drop effect reflects that the drop cannot occur.
    If Not (e.Data.GetDataPresent(GetType(System.String))) Then

        e.Effect = DragDropEffects.None
        DropLocationLabel.Text = "None - no string data."
        Return
    End If

    ' Set the effect based upon the KeyState.
    If ((e.KeyState And (8 + 32)) = (8 + 32) And
        (e.AllowedEffect And DragDropEffects.Link) = DragDropEffects.Link) Then
        ' KeyState 8 + 32 = CTRL + ALT

        ' Link drag-and-drop effect.
        e.Effect = DragDropEffects.Link

    ElseIf ((e.KeyState And 32) = 32 And
        (e.AllowedEffect And DragDropEffects.Link) = DragDropEffects.Link) Then

        ' ALT KeyState for link.
        e.Effect = DragDropEffects.Link

    ElseIf ((e.KeyState And 4) = 4 And
        (e.AllowedEffect And DragDropEffects.Move) = DragDropEffects.Move) Then

        ' SHIFT KeyState for move.
        e.Effect = DragDropEffects.Move

    ElseIf ((e.KeyState And 8) = 8 And
        (e.AllowedEffect And DragDropEffects.Copy) = DragDropEffects.Copy) Then

        ' CTRL KeyState for copy.
        e.Effect = DragDropEffects.Copy

    ElseIf ((e.AllowedEffect And DragDropEffects.Move) = DragDropEffects.Move) Then

        ' By default, the drop action should be move, if allowed.
        e.Effect = DragDropEffects.Move

    Else
        e.Effect = DragDropEffects.None
    End If

    ' Gets the index of the item the mouse is below. 

    ' The mouse locations are relative to the screen, so they must be 
    ' converted to client coordinates.

    indexOfItemUnderMouseToDrop =
        ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(New Point(e.X, e.Y)))

    ' Updates the label text.
    If (indexOfItemUnderMouseToDrop <> ListBox.NoMatches) Then
        DropLocationLabel.Text = "Drops before item #" & (indexOfItemUnderMouseToDrop + 1)
    Else
        DropLocationLabel.Text = "Drops at the end."
    End If

End Sub

Açıklamalar

Sürükle DragOver ve bırak işlemi sırasında fare imleci denetimin sınırları içinde hareket ettiğinde olay tetikler.

Aşağıda sürükle ve bırak işlemleriyle ilgili olayların nasıl ve ne zaman tetiklediği açıklanmaktadır.

yöntemi, DoDragDrop geçerli imleç konumu altındaki denetimi belirler. Ardından denetimin geçerli bir bırakma hedefi olup olmadığını denetler.

Denetim geçerli bir bırakma hedefiyse, GiveFeedback olay sürükle ve bırak efekti belirtilen şekilde oluşturulur. Sürükle ve bırak efektlerinin listesi için numaralandırmaya DragDropEffects bakın.

Fare imleci konumu, klavye durumu ve fare düğmesi durumundaki değişiklikler izlenir.

  • Kullanıcı bir pencereden dışarı taşınırsa, DragLeave olay tetikler.

  • Fare başka bir denetime girerse, DragEnter bu denetimin değeri yükseltilir.

  • Fare hareket eder ancak aynı denetim içinde kalırsa olay DragOver tetikler.

Klavye veya fare düğmesi durumunda bir değişiklik olursa, QueryContinueDrag olay oluşturulur ve sürüklemeye devam etmek, verileri bırakmak veya olayın özelliğinin Action değerine göre işlemi iptal etmek isteyip istemediğinizi QueryContinueDragEventArgsbelirler.

  • Değerin DragAction değeri iseContinueDragOver, işleme devam etmek için olay oluşturulur ve uygun görsel geri bildirimin ayarlanabilmesi GiveFeedback için olay yeni etkiyle oluşturulur. Geçerli bırakma efektlerinin listesi için numaralandırmaya DragDropEffects bakın.

    Not

    DragOver ve GiveFeedback olayları eşlenir, böylece fare bırakma hedefi boyunca hareket ettikçe kullanıcıya farenin konumuyla ilgili en güncel geri bildirim verilir.

  • değeri DragAction ise Drop, bırakma efekti değeri kaynağa döndürülür, böylece kaynak uygulama kaynak veriler üzerinde uygun işlemi gerçekleştirebilir; örneğin, işlem bir taşıma işlemiyse verileri kesin.

  • değeri DragAction iseCancelDragLeave, olay oluşturulur.

    Not

    ve XY özellikleri DragEventArgs , istemci koordinatlarında değil ekran koordinatlarındadır. Aşağıdaki C# kodu satırı, özellikleri bir istemciye Pointdönüştürür:

    Point clientPoint = targetControl.PointToClient(new Point(de. X, de. Y));

Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

Şunlara uygulanır

Ayrıca bkz.