다음을 통해 공유


DragEventArgs.Effect 속성

끌어서 놓기 작업에서 대상 놓기 결과를 가져오거나 설정합니다.

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

구문

‘선언
Public Property Effect As DragDropEffects
‘사용 방법
Dim instance As DragEventArgs
Dim value As DragDropEffects

value = instance.Effect

instance.Effect = value
public DragDropEffects Effect { get; set; }
public:
property DragDropEffects Effect {
    DragDropEffects get ();
    void set (DragDropEffects value);
}
/** @property */
public DragDropEffects get_Effect ()

/** @property */
public void set_Effect (DragDropEffects value)
public function get Effect () : DragDropEffects

public function set Effect (value : DragDropEffects)

속성 값

DragDropEffects 값 중 하나입니다.

설명

기본적으로 적용되는 결과에 따라 끌어서 놓기 작업 대상의 마우스 커서가 결정됩니다. 이를 통해 발생될 작업을 사용자에게 미리 알릴 수 있습니다. 예를 들어, 소스에서 파일을 끌 때 Ctrl 키를 누르는 경우 DragDropEffects.Copy를 지정하여 대상에서 복사 작업을 시도할 것임을 나타낼 수 있습니다.

끌기 작업에 대해 사용자 지정 커서를 사용하려면 GiveFeedbackEventArgs.UseDefaultCursors를 참조하십시오.

예제

다음 예제에서는 두 개의 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 이벤트 처리기에서 끌어서 놓기 작업이 취소됩니다.

인용된 이 코드에서는 DragEventArgs 클래스를 사용하는 방법을 보여 줍니다. 전체 코드 예제를 보려면 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에서 지원

참고 항목

참조

DragEventArgs 클래스
DragEventArgs 멤버
System.Windows.Forms 네임스페이스
DragDropEffects 열거형