共用方式為


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 ,並將 屬性設定 AllowItemReorderfalse ,以回應您在 、 ToolStripItem.DragLeaveToolStripItem.DragDrop 事件中 ToolStripItem.DragEnter 定義的拖放行為。

AllowDrop 屬性設定為 false ,並將 屬性設定 AllowItemReordertrue ,讓 ToolStripItem 類別私下處理拖放和專案重新排序。

將 和 AllowItemReorder 屬性設定 AllowDroptrue 會擲回例外狀況。

適用於