Control.DragOver 이벤트

정의

개체를 컨트롤의 범위 위로 끌 때 발생합니다.

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 

이벤트 유형

예제

다음 코드 예제에서는 두 ListBox 컨트롤 간의 끌어서 놓기 작업을 보여 줍니다. 예제에서는 호출을 DoDragDrop 끌기 작업이 시작 될 때 메서드. 마우스를 이동 하는 경우 끌기 작업이 시작 둘 SystemInformation.DragSize 하는 동안 마우스 위치에서의 MouseDown 이벤트입니다. 합니다 IndexFromPoint 메서드를 사용 하는 동안 끌어서 항목의 인덱스를 확인 합니다 MouseDown 이벤트입니다.

또한이 사용자 지정 커서를 사용 하 여 끌어서 놓기 작업에 대 한 예제입니다. 예제를 실행 하려면 커서 파일인 3dwarro.cur3dwno.cur, 사용자 지정 끌기에 대 한 애플리케이션 디렉터리에 존재 놓기-커서, 각각. 사용자 지정 커서를 사용할 경우는 UseCustomCursorsCheckCheckBox 확인란이 선택 되어 있습니다. 에 설정 된 사용자 지정 커서를 GiveFeedback 이벤트 처리기입니다.

키보드 상태는 오른쪽 ListBox에 대한 이벤트 처리기에서 DragOver 평가되어 Shift, Ctrl, Alt 또는 Ctrl+Alt 키의 상태를 기반으로 하는 끌기 작업을 결정합니다. 위치는 ListBox 하는 동안 결정 됩니다 드롭다운 수행 되는 DragOver 이벤트입니다. 삭제할 데이터가 이 아닌 StringDragEventArgs.Effect 경우 는 에서 로 NoneDragDropEffects설정됩니다. 드롭다운의 상태에 표시 됩니다는 마지막으로, 합니다 DropLocationLabelLabel합니다.

데이터를 오른쪽에 대 한 drop ListBox 에서 결정 됩니다는 DragDrop 이벤트 처리기 및 String 값에 적절 한 위치에 추가 됩니다는 ListBox. 끌기 작업 이동 폼의 범위를 벗어나는 경우에서 끌어서 놓기 작업이 취소 되는 QueryContinueDrag 이벤트 처리기입니다.

이 코드 발췌에서는 이벤트를 사용하는 방법을 보여 줍니다 DragOver . 참조 된 DoDragDrop 전체 코드 예제에 대 한 메서드.

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

설명

DragOver 이벤트는 끌어서 놓기 작업 중 컨트롤의 범위 내에서 마우스 커서를 이동 하면 발생 합니다.

다음에서는 끌어서 놓기 작업이 발생하는 방식 및 시기에 대해 설명합니다.

메서드는 DoDragDrop 현재 커서 위치 아래의 컨트롤을 결정합니다. 그런 다음 컨트롤이 유효한 놓기 대상인지 확인합니다.

컨트롤이 유효한 놓기 대상인 GiveFeedback 경우 끌어서 놓기 효과가 지정된 상태에서 이벤트가 발생합니다. 끌어서 놓기 작업 결과 목록에 대한 자세한 내용은 DragDropEffects 열거형을 참조하십시오.

마우스 커서 위치, 키보드 상태 및 마우스 단추 상태의 변경 내용을 추적합니다.

  • 사용자가 창의 외부로 이동하면 DragLeave 이벤트가 발생합니다.

  • 마우스를 다른 컨트롤로 가져가면 해당 컨트롤에 대한 DragEnter가 발생합니다.

  • 마우스를 동일한 컨트롤 내에서 이동하면 DragOver 이벤트가 발생합니다.

키보드 또는 마우스 단추 상태가 QueryContinueDrag 변경되면 이벤트가 발생하고 끌기를 계속할지, 데이터를 삭제할지, 아니면 이벤트의 QueryContinueDragEventArgs속성 값 Action 에 따라 작업을 취소할지 결정합니다.

  • DragAction 값이 이 ContinueDragOver 면 작업을 계속 GiveFeedback 하기 위해 이벤트가 발생하고 적절한 시각적 피드백을 설정할 수 있도록 새 효과와 함께 이벤트가 발생합니다. 유효한 끌어서 놓기 작업 결과 목록에 대한 자세한 내용은 DragDropEffects 열거형을 참조하십시오.

    참고

    DragOverGiveFeedback 이벤트는 마우스가 놓기 대상을 가로질러 이동할 때 사용자에게 마우스 위치에 대한 최신 피드백이 제공되도록 페어링됩니다.

  • 경우 값 DragActionDrop놓기 결과 값이 소스로 반환은, 원본 애플리케이션은 원본 데이터에 대해 적절 한 작업을 수행할 수 있도록 예의 경우 데이터 잘라내기 작업이 이동 합니다.

  • DragActionCancelDragLeave 이 이면 이벤트가 발생합니다.

    참고

    DragEventArgsY 속성은 X 클라이언트 좌표가 아닌 화면 좌표에 있습니다. 다음 C# 코드 줄은 속성을 클라이언트 Point로 변환합니다.

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

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보