DragDropEffects DragDropEffects DragDropEffects DragDropEffects Enum

定义

指定拖放操作的可能效果。Specifies the possible effects of a drag-and-drop operation.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class DragDropEffects
[System.Flags]
public enum DragDropEffects
type DragDropEffects = 
Public Enum DragDropEffects
继承
DragDropEffectsDragDropEffectsDragDropEffectsDragDropEffects
属性

字段

All All All All -2147483645

CopyMoveScroll 效果的组合。The combination of the Copy, Move, and Scroll effects.

Copy Copy Copy Copy 1

将拖动源中的数据复制到放置目标。The data from the drag source is copied to the drop target.

4

将拖动源中的数据链接到放置目标。The data from the drag source is linked to the drop target.

Move Move Move Move 2

将拖动源的数据移动到放置目标。The data from the drag source is moved to the drop target.

None None None None 0

放置目标不接受该数据。The drop target does not accept the data.

Scroll Scroll Scroll Scroll -2147483648

拖动时可以滚动目标,以定位在目标中当前不可见的某个放置位置。The target can be scrolled while dragging to locate a drop position that is not currently visible in the target.

示例

此代码示例演示了如何使用Copy枚举时用户拖放操作期间将鼠标移到放置目标上。This code example demonstrates using the Copy enumeration when the user moves the mouse over the drop target during a drag-and-drop operation. 此代码示例是为提供一个更大示例的一部分DoDragDrop方法的Control类。This code example is part of a larger example provided for the DoDragDrop method of the Control class. 请参阅DoDragDrop完整的代码示例的方法。See the DoDragDrop method for the complete code example.

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

注解

此枚举由以下类: DragEventArgsGiveFeedbackEventArgs,和ControlThis enumeration is used by the following classes: DragEventArgs, GiveFeedbackEventArgs, and Control.

可以使用DragDropEffects以显示不同的鼠标指针拖放操作。You can use DragDropEffects to display different mouse pointers for drag-and-drop operations. 例如,可以显示加号复制拖放操作移动拖放操作,箭头符号或带有贯穿线的红色圆圈符号没有一个拖放操作。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.

如果你想要在中当前不可见的目标位置删除数据,您无法同时拖动滚动目标。If you want to drop data at a position in the target that is not currently visible, you could scroll the target while dragging. 如果目标不支持滚动,必须确保在开始拖放操作之前放置位置是在目标中可见。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. 以下是你可能想要滚动目标一些方案:The following are some scenarios when you might want to scroll a target:

  • 将文本拖动到文档中,并且你想要将文本放在文档窗口中不可见的位置。You are dragging text into a document, and you want to drop the text at a position not visible in the document window.

  • 您将文件拖动到文件树中,并且你想要将文件放置在文件树中不可见的节点。You are dragging a file into a file tree, and you want to drop the file on a node not visible in the file tree.

适用于

另请参阅