ToolStrip.AllowDrop 屬性


取得或設定值,指出拖放和項目的重新排列是否透過您實作的事件來加以處理。Gets or sets a value indicating whether drag-and-drop and item reordering are handled through events that you implement.

 virtual property bool AllowDrop { bool get(); void set(bool value); };
public override bool AllowDrop { get; set; }
member this.AllowDrop : bool with get, set
Public Overrides Property AllowDrop As Boolean



true 表示透過您所實作的事件來控制拖放和項目的重新排列,否則為 falsetrue to control drag-and-drop and item reordering through events that you implement; otherwise, false.


AllowDropAllowItemReorder 都會設定為 trueAllowDrop and AllowItemReorder are both set to true.


下列程式碼範例將示範設定通用屬性的語法 ToolStrip ,包括 AllowDrop 屬性。The following code example demonstrates the syntax for setting common ToolStrip properties, including the AllowDrop property.

// This is an example of some common ToolStrip property settings.
toolStrip1.AllowDrop = false;
toolStrip1.AllowItemReorder = true;
toolStrip1.AllowMerge = false;
toolStrip1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
toolStrip1.AutoSize = false;
toolStrip1.CanOverflow = false;
toolStrip1.Cursor = System.Windows.Forms.Cursors.Cross;
toolStrip1.DefaultDropDownDirection = System.Windows.Forms.ToolStripDropDownDirection.BelowRight;
toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
toolStrip1.GripMargin = new System.Windows.Forms.Padding(3);
toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
toolStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
toolStrip1.Location = new System.Drawing.Point(0, 0);
toolStrip1.Margin = new System.Windows.Forms.Padding(1);
toolStrip1.Name = "toolStrip1";
toolStrip1.Padding = new System.Windows.Forms.Padding(0, 0, 2, 0);
toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
toolStrip1.ShowItemToolTips = false;
toolStrip1.Size = new System.Drawing.Size(109, 273);
toolStrip1.Stretch = true;
toolStrip1.TabIndex = 0;
toolStrip1.TabStop = true;
toolStrip1.Text = "toolStrip1";
toolStrip1.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90;
' This is an example of some common ToolStrip property settings.
toolStrip1.AllowDrop = False
toolStrip1.AllowItemReorder = True
toolStrip1.AllowMerge = False
toolStrip1.Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles)
toolStrip1.AutoSize = False
toolStrip1.CanOverflow = False
toolStrip1.Cursor = Cursors.Cross
toolStrip1.Dock = System.Windows.Forms.DockStyle.None
toolStrip1.DefaultDropDownDirection = ToolStripDropDownDirection.BelowRight
toolStrip1.GripMargin = New System.Windows.Forms.Padding(3)
toolStrip1.ImageScalingSize = New System.Drawing.Size(20, 20)
toolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {toolStripButton1})
toolStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow
toolStrip1.Location = New System.Drawing.Point(0, 0)
toolStrip1.Margin = New System.Windows.Forms.Padding(1)
toolStrip1.Name = "toolStrip1"
toolStrip1.Padding = New System.Windows.Forms.Padding(0, 0, 2, 0)
toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
toolStrip1.ShowItemToolTips = False
toolStrip1.Size = New System.Drawing.Size(109, 273)
toolStrip1.Stretch = True
toolStrip1.TabIndex = 0
toolStrip1.TabStop = True
toolStrip1.Text = "toolStrip1"
toolStrip1.TextDirection = System.Windows.Forms.ToolStripTextDirection.Vertical90


AllowDrop 屬性設為, true 並將 AllowItemReorder 屬性設定為 false ,以回應您在 Control.DragEnterControl.DragLeave 和事件中定義的拖放行為 Control.DragDropSet the AllowDrop property to true and set the AllowItemReorder property to false to respond to drag-and-drop behavior you have defined in the Control.DragEnter, Control.DragLeave, and Control.DragDrop events.

將設定 AllowDropfalse ,並將設定 AllowItemReorder 為, trueToolStrip 類別自動處理拖放和專案的重新排列。Set AllowDrop to false and set AllowItemReorder to true to cause the ToolStrip class to handle drag-and-drop and item reordering automatically. AllowItemReorder true 針對兩個物件將設定為, ToolStrip 以允許將專案從一個拖曳 ToolStrip 到另一個。Set AllowItemReorder to true for two ToolStrip objects to allow dragging of items from one ToolStrip to the other. 若要啟用預設拖放,必須在拖曳作業期間按下 ALT 鍵。To enable the default drag-and-drop, the ALT key must be pressed during the drag operation.

同時設定和會擲回 AllowDrop AllowItemReorder 例外狀況 trueSetting both AllowDrop and AllowItemReorder to true throws an exception.