DragDropEffects Enumeración

Definición

Especifica los efectos posibles de una operación de arrastrar y colocar.Specifies the possible effects of a drag-and-drop operation.

Esta enumeración tiene el atributo FlagsAttribute, que permite una combinación bit a bit de sus valores de miembro.

public enum class DragDropEffects
[System.Flags]
public enum DragDropEffects
type DragDropEffects = 
Public Enum DragDropEffects
Herencia
DragDropEffects
Atributos

Campos

All -2147483645

Combinación de los efectos de Copy, Move y Scroll.The combination of the Copy, Move, and Scroll effects.

Copy 1

Los datos del origen de arrastre se copian en el destino de colocación.The data from the drag source is copied to the drop target.

4

Los datos del origen (arrastrar) se vinculan al destino (colocar).The data from the drag source is linked to the drop target.

Move 2

Los datos del origen (arrastrar) se mueven al destino (colocar).The data from the drag source is moved to the drop target.

None 0

El destino (colocar) no acepta los datos.The drop target does not accept the data.

Scroll -2147483648

El destino se puede desplazar mientras se arrastra para buscar una posición de colocación que no está actualmente visible en el destino.The target can be scrolled while dragging to locate a drop position that is not currently visible in the target.

Ejemplos

En el ejemplo siguiente se muestra DragDropEffects cómo usar la enumeración cuando el usuario mueve el mouse sobre el destino de colocación durante una operación de arrastrar y colocar.The following example demonstrates using the DragDropEffects enumeration when the user moves the mouse over the drop target during a drag-and-drop operation. Este ejemplo forma parte de un ejemplo mayor proporcionado para el Control.DoDragDrop método.This example is part of a larger example provided for the Control.DoDragDrop method.

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

}
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

Comentarios

Esta enumeración se usa en DragEventArgslas GiveFeedbackEventArgsclases, Control y.This enumeration is used by the DragEventArgs, GiveFeedbackEventArgs, and Control classes.

Puede usar DragDropEffects para mostrar distintos punteros del mouse para las operaciones de arrastrar y colocar.You can use DragDropEffects to display different mouse pointers for drag-and-drop operations. Por ejemplo, puede mostrar un símbolo más para una Copy operación de arrastrar y colocar, un símbolo de flecha para una Move operación de arrastrar y colocar, o un círculo rojo con una línea a través de su símbolo para una None operación de arrastrar y colocar.For example, you can display a plus symbol for a Copy drag-and-drop operation, an arrow symbol for a Move drag-and-drop operation, or a red circle with a line through it symbol for a None drag-and-drop operation.

Si desea colocar los datos en una posición del destino que no está visible actualmente, puede desplazarse por el destino mientras arrastra.If you want to drop data at a position in the target that is not currently visible, you could scroll the target while dragging. Si un destino no admite el desplazamiento, debe asegurarse de que la posición de colocación es visible en el destino antes de comenzar la operación de arrastrar y colocar.If a target does not support scrolling, you must make sure that the drop position is visible in the target before you begin the drag-and-drop operation. A continuación se muestran algunos escenarios en los que es posible que desee desplazarse por un destino:The following are some scenarios when you might want to scroll a target:

  • Está arrastrando texto a un documento y desea colocar el texto en una posición no visible en la ventana de documento.You're dragging text into a document, and you want to drop the text at a position not visible in the document window.

  • Está arrastrando un archivo a un árbol de archivos y desea colocar el archivo en un nodo no visible en el árbol de archivos.You're dragging a file into a file tree, and you want to drop the file on a node not visible in the file tree.

Se aplica a

Consulte también: