Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ToolStripItem.AllowDrop Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets a value indicating whether drag-and-drop and item reordering are handled through events that you implement.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public virtual bool AllowDrop { get; set; }
/** @property */
public boolean get_AllowDrop ()

/** @property */
public void set_AllowDrop (boolean value)

public function get AllowDrop () : boolean

public function set AllowDrop (value : boolean)

Property Value

true if drag-and-drop operations are allowed in the control; otherwise, false. The default is false.
Exception typeCondition

ArgumentException

AllowDrop and AllowItemReorder are both set to true.

Set the AllowDrop property to true and set the AllowItemReorder property to false to respond to drag-and-drop behavior you have defined in the ToolStripItem.DragEnter, ToolStripItem.DragLeave, and ToolStripItem.DragDrop events.

Set the AllowDrop property to false and set the AllowItemReorder property to true to cause the ToolStripItem class to handle drag-and-drop and item reordering privately.

Setting both the AllowDrop and the AllowItemReorder properties to true throws an exception.

The following code example demonstrates how to set the AllowDrop property. This code example is part of a larger example provided for the ToolStripItem class.

// 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;
}

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.