ToolStripItem.AllowDrop 属性

定义

获取或设置一个值,该值指示是否通过你实现的事件来处理拖放和项重新排序。

public:
 virtual property bool AllowDrop { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public virtual bool AllowDrop { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.AllowDrop : bool with get, set
Public Overridable Property AllowDrop As Boolean

属性值

如果控件允许拖放操作,则为 true;否则为 false。 默认值为 false

属性

例外

AllowDropAllowItemReorder 均设置为 true

示例

下面的代码示例演示如何设置 AllowDrop 属性。 此代码示例是为 ToolStripItem 类提供的一个更大示例的一部分。

// This utility method creates a RolloverItem 
// and adds it to a ToolStrip control.
private RolloverItem CreateRolloverItem(
    ToolStrip owningToolStrip,
    string txt,
    Font f,
    string imgKey,
    TextImageRelation tir,
    string backImgKey)
{
    RolloverItem item = new RolloverItem();

    item.Alignment = ToolStripItemAlignment.Left;
    item.AllowDrop = false;
    item.AutoSize = true;

    item.BackgroundImage = owningToolStrip.ImageList.Images[backImgKey];
    item.BackgroundImageLayout = ImageLayout.Center;
    item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
    item.DoubleClickEnabled = true;
    item.Enabled = true;
    item.Font = f;

    // These assignments are equivalent. Each assigns an
    // image from the owning toolstrip's image list.
    item.ImageKey = imgKey;
    //item.Image = owningToolStrip.ImageList.Images[infoIconKey];
    //item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
    item.ImageScaling = ToolStripItemImageScaling.None;

    item.Owner = owningToolStrip;
    item.Padding = new Padding(2);
    item.Text = txt;
    item.TextAlign = ContentAlignment.MiddleLeft;
    item.TextDirection = ToolStripTextDirection.Horizontal;
    item.TextImageRelation = tir;

    return item;
}
' This utility method creates a RolloverItem 
' and adds it to a ToolStrip control.
 Private Function CreateRolloverItem( _
 ByVal owningToolStrip As ToolStrip, _
 ByVal txt As String, _
 ByVal f As Font, _
 ByVal imgKey As String, _
 ByVal tir As TextImageRelation, _
 ByVal backImgKey As String) As RolloverItem

     Dim item As New RolloverItem()

     item.Alignment = ToolStripItemAlignment.Left
     item.AllowDrop = False
     item.AutoSize = True

     item.BackgroundImage = owningToolStrip.ImageList.Images(backImgKey)
     item.BackgroundImageLayout = ImageLayout.Center
     item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
     item.DoubleClickEnabled = True
     item.Enabled = True
     item.Font = f

     ' These assignments are equivalent. Each assigns an
     ' image from the owning toolstrip's image list.
     item.ImageKey = imgKey
     'item.Image = owningToolStrip.ImageList.Images[infoIconKey];
     'item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
     item.ImageScaling = ToolStripItemImageScaling.None

     item.Owner = owningToolStrip
     item.Padding = New Padding(2)
     item.Text = txt
     item.TextAlign = ContentAlignment.MiddleLeft
     item.TextDirection = ToolStripTextDirection.Horizontal
     item.TextImageRelation = tir

     Return item
 End Function

注解

AllowDrop 属性true设置为 ,并将 AllowItemReorder 属性false设置为 以响应在 、 ToolStripItem.DragLeaveToolStripItem.DragDrop 事件中ToolStripItem.DragEnter定义的拖放行为。

AllowDrop 属性设置为 false ,并将 AllowItemReorder 属性设置为 , true 使 ToolStripItem 类以私密方式处理拖放和项重新排序。

将 和 AllowItemReorder 属性都AllowDrop设置为 会true引发异常。

适用于