다음을 통해 공유


DragDropEffects 열거형

끌어서 놓기 작업의 효과를 지정합니다.

이 열거형에는 멤버 값를 비트로 조합할 수 있는 FlagsAttribute 특성이 있습니다.

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

구문

‘선언
<FlagsAttribute> _
Public Enumeration DragDropEffects
‘사용 방법
Dim instance As DragDropEffects
[FlagsAttribute] 
public enum DragDropEffects
[FlagsAttribute] 
public enum class DragDropEffects
/** @attribute FlagsAttribute() */ 
public enum DragDropEffects
FlagsAttribute 
public enum DragDropEffects

멤버

  멤버 이름 설명
All 데이터가 복사되고 끌기 소스에서 제거된 다음 놓기 대상에 스크롤됩니다. 
Copy 데이터가 놓기 대상에 복사됩니다. 
Link 끌기 소스의 데이터가 놓기 대상에 링크됩니다. 
Move 끌기 소스의 데이터가 놓기 대상으로 이동됩니다. 
None 놓기 대상이 데이터를 허용하지 않습니다. 
Scroll 스크롤 작업이 막 시작하려는 중이였거나 놓기 대상에서 현재 진행 중입니다. 

설명

이 열거형은 DragEventArgs, GiveFeedbackEventArgsControl 클래스에서 사용됩니다.

예제

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

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

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

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

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

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 = CTL + 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

        ' CTL 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
private 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(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 = CTL + 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) {

        // CTL 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.";

}
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 = CTL + 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) )
   {
      // CTL 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, 
    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.get_Data().GetDataPresent(String.class.ToType()))) {
        e.set_Effect(DragDropEffects.None);
        dropLocationLabel.set_Text("None - no string data.");
        return;
    }
    // Set the effect based upon the KeyState.
    if ((e.get_KeyState() & 8 + 32) == 8 + 32 && (e.get_AllowedEffect() 
        & DragDropEffects.Link) == DragDropEffects.Link) {
        // KeyState 8 + 32 = CTL + ALT
        // Link drag-and-drop effect.
        e.set_Effect(DragDropEffects.Link);
    }
    else {
        if ((e.get_KeyState() & 32) == 32 && (e.get_AllowedEffect() 
            & DragDropEffects.Link) == DragDropEffects.Link) {
            // ALT KeyState for link.
            e.set_Effect(DragDropEffects.Link);
        }
        else {
            if ((e.get_KeyState() & 4) == 4 && (e.get_AllowedEffect() 
                & DragDropEffects.Move) == DragDropEffects.Move) {
                // SHIFT KeyState for move.
                e.set_Effect(DragDropEffects.Move);
            }
            else {
                if ((e.get_KeyState() & 8) == 8 && (e.get_AllowedEffect() 
                    & DragDropEffects.Copy) == DragDropEffects.Copy) {
                    // CTL KeyState for copy.
                    e.set_Effect(DragDropEffects.Copy);
                }
                else {
                    if ((e.get_AllowedEffect() & DragDropEffects.Move) 
                        == DragDropEffects.Move) {
                        // By default, the drop action should be move, 
                        //if allowed.
                        e.set_Effect(DragDropEffects.Move);
                    }
                    else {
                        e.set_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.get_X(), e.get_Y())));
    // Updates the label text.
    if (indexOfItemUnderMouseToDrop != ListBox.NoMatches) {
        dropLocationLabel.set_Text("Drops before item #" 
            + (indexOfItemUnderMouseToDrop + 1));
    }
    else {
        dropLocationLabel.set_Text("Drops at the end.");
    }
} //listDragTarget_DragOver

플랫폼

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에서 지원

참고 항목

참조

System.Windows.Forms 네임스페이스
DragEventArgs
GiveFeedbackEventArgs