다음을 통해 공유


Control.QueryContinueDrag 이벤트

끌어서 놓기 작업 중에 발생하며 끌기 소스가 끌어서 놓기 작업을 취소해야 할지 여부를 결정하도록 합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Event QueryContinueDrag As QueryContinueDragEventHandler
‘사용 방법
Dim instance As Control
Dim handler As QueryContinueDragEventHandler

AddHandler instance.QueryContinueDrag, handler
public event QueryContinueDragEventHandler QueryContinueDrag
public:
event QueryContinueDragEventHandler^ QueryContinueDrag {
    void add (QueryContinueDragEventHandler^ value);
    void remove (QueryContinueDragEventHandler^ value);
}
/** @event */
public void add_QueryContinueDrag (QueryContinueDragEventHandler value)

/** @event */
public void remove_QueryContinueDrag (QueryContinueDragEventHandler value)
JScript에서는 이벤트를 사용할 수 있지만 새로 선언할 수는 없습니다.

설명

끌어서 놓기 작업을 수행하는 동안 키보드 또는 마우스 단추 상태가 변경되면 QueryContinueDrag 이벤트가 발생합니다. QueryContinueDrag 이벤트를 사용하면 끌기 소스에서 끌어서 놓기 작업이 취소되어야 하는지 여부를 확인할 수 있습니다.

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

DoDragDrop 메서드는 현재 커서 위치에서 컨트롤을 확인합니다. 그런 다음 컨트롤이 유효한 놓기 대상인지 여부를 확인합니다.

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

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

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

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

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

키보드 또는 마우스 단추 상태를 변경하면 QueryContinueDrag 이벤트가 발생하여 해당 이벤트의 QueryContinueDragEventArgs에 대한 Action 속성 값을 기반으로 끌기를 계속하거나, 데이터를 놓거나, 작업을 취소할지를 결정할 수 있습니다.

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

    참고

    DragOverGiveFeedback 이벤트는 쌍을 이루기 때문에 마우스가 놓기 대상을 통과할 때 사용자에게 마우스 위치에 대한 최신 피드백이 제공됩니다.

  • DragAction의 값이 Drop이면 놓기 결과 값이 소스로 반환되므로 소스 응용 프로그램은 소스 데이터에 대해 적절한 작업(예: 이동 작업의 경우 데이터 잘라내기)을 수행할 수 있습니다.

  • DragAction의 값이 Cancel이면 DragLeave 이벤트가 발생합니다.

기본적으로 Esc 키를 누르면 QueryContinueDrag 이벤트는 ActionDragActionCancel로 설정하고 마우스 왼쪽, 가운데 또는 오른쪽 단추를 누르면 ActionDragActionDrop으로 설정합니다.

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

예제

다음 코드 예제에서는 두 개의 ListBox 컨트롤 간에 수행되는 끌어서 놓기 작업을 보여 줍니다. 다음 예제에서는 끌기가 시작될 때 DoDragDrop 메서드가 호출됩니다. MouseDown 이벤트가 발생하는 동안 마우스 위치로부터 SystemInformation.DragSize 이상 마우스를 이동하면 끌기 작업이 시작됩니다. IndexFromPoint 메서드는 MouseDown 이벤트가 발생하는 동안 끌어 올 항목의 인덱스를 확인하는 데 사용됩니다.

또한 다음 예제에서는 끌어서 놓기 작업에 대해 사용자 지정 커서를 사용하는 방법을 보여 줍니다. 이 예제를 실행하려면 각각 사용자 지정 끌기와 놓기 못함 커서에 대한 3dwarro.cur3dwno.cur 커서 파일이 응용 프로그램 디렉터리에 있어야 합니다. UseCustomCursorsCheckCheckBox를 선택하면 사용자 지정 커서가 사용됩니다. 사용자 지정 커서는 GiveFeedback 이벤트 처리기에서 설정됩니다.

Shift, Ctrl, Alt 또는 Ctrl+Alt 중 끌기 작업을 수행하는 데 사용할 키 상태를 결정하기 위해 오른쪽 ListBoxDragOver 이벤트 처리기에서 키보드 상태가 확인됩니다. DragOver 이벤트가 수행되는 동안 ListBox에서 끌어 놓기가 발생한 위치도 확인됩니다. 끌어올 데이터가 String이 아니면 DragDropEffects에서 DragEventArgs.EffectNone으로 설정됩니다. 마지막으로 끌어 놓기 상태가 DropLocationLabelLabel에 표시됩니다.

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

인용된 이 코드에서는 QueryContinueDrag 이벤트를 사용하는 방법을 보여 줍니다. 전체 코드 예제를 보려면 DoDragDrop 메서드를 참조하십시오.

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, System.Windows.Forms.ListBox)

    If Not (lb is 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
private void ListDragSource_QueryContinueDrag(object sender, System.Windows.Forms.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;
        }
    }
}
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, 
    System.Windows.Forms.QueryContinueDragEventArgs e)
{
    // Cancel the drag if the mouse moves off the form.
    ListBox lb = (ListBox)sender;

    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.get_MousePosition().get_X() - screenOffset.get_X() 
            < f.get_DesktopBounds().get_Left() 
            || Control.get_MousePosition().get_X() 
            - screenOffset.get_X() > f.get_DesktopBounds().get_Right() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            < f.get_DesktopBounds().get_Top() 
            || Control.get_MousePosition().get_Y() - screenOffset.get_Y() 
            > f.get_DesktopBounds().get_Bottom()) {
            e.set_Action(DragAction.Cancel);
        }
    }
} //listDragSource_QueryContinueDrag

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
OnQueryContinueDrag