ToolStripItem.AutoSize 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否自动调整项的大小。
public:
property bool AutoSize { bool get(); void set(bool value); };
public bool AutoSize { get; set; }
member this.AutoSize : bool with get, set
Public Property AutoSize As Boolean
属性值
如果自动调整 ToolStripItem 的大小,为 true
;否则为 false
。 默认值是 true
。
示例
下面的代码示例演示如何设置 Text、 AutoSize、 Overflow和 TextDirection 属性并处理 Click 事件。 若要运行此示例,请将以下代码粘贴到包含ToolStrip名为 movingToolStrip
的窗体中,并在窗体的构造函数或Load
事件处理程序中调用 InitializeMovingToolStrip
。
ToolStripButton^ changeDirectionButton;
void InitializeMovingToolStrip()
{
changeDirectionButton = gcnew ToolStripButton;
movingToolStrip->AutoSize = true;
movingToolStrip->RenderMode = ToolStripRenderMode::System;
changeDirectionButton->TextDirection =
ToolStripTextDirection::Vertical270;
changeDirectionButton->Overflow =
ToolStripItemOverflow::Never;
changeDirectionButton->Text = "Change Alignment";
movingToolStrip->Items->Add(changeDirectionButton);
changeDirectionButton->Click += gcnew EventHandler(this,
&Form1::changeDirectionButtonClick);
}
void changeDirectionButtonClick(Object^ sender, EventArgs^ e)
{
ToolStripItem^ item = (ToolStripItem^) sender;
if ((item->TextDirection == ToolStripTextDirection::Vertical270)
|| (item->TextDirection == ToolStripTextDirection::Vertical90))
{
item->TextDirection = ToolStripTextDirection::Horizontal;
movingToolStrip->Raft = RaftingSides::Top;
}
else
{
item->TextDirection =
ToolStripTextDirection::Vertical270;
movingToolStrip->Raft = RaftingSides::Left;
}
}
internal ToolStripButton changeDirectionButton;
private void InitializeMovingToolStrip()
{
movingToolStrip = new ToolStrip();
changeDirectionButton = new ToolStripButton();
movingToolStrip.AutoSize = true;
movingToolStrip.RenderMode = ToolStripRenderMode.System;
changeDirectionButton.TextDirection = ToolStripTextDirection.Vertical270;
changeDirectionButton.Overflow = ToolStripItemOverflow.Never;
changeDirectionButton.Text = "Change Alignment";
movingToolStrip.Items.Add(changeDirectionButton);
}
private void changeDirectionButton_Click(object sender, EventArgs e)
{
ToolStripItem item = (ToolStripItem)sender;
if (item.TextDirection == ToolStripTextDirection.Vertical270 || item.TextDirection == ToolStripTextDirection.Vertical90)
{
item.TextDirection = ToolStripTextDirection.Horizontal;
movingToolStrip.Dock = System.Windows.Forms.DockStyle.Top;
}
else
{
item.TextDirection = ToolStripTextDirection.Vertical270;
movingToolStrip.Dock = System.Windows.Forms.DockStyle.Left;
}
}
Friend WithEvents changeDirectionButton As ToolStripButton
Private Sub InitializeMovingToolStrip()
changeDirectionButton = New ToolStripButton()
movingToolStrip.AutoSize = True
movingToolStrip.RenderMode = ToolStripRenderMode.System
changeDirectionButton.TextDirection = ToolStripTextDirection.Vertical270
changeDirectionButton.Overflow = ToolStripItemOverflow.Never
changeDirectionButton.Text = "Change Alignment"
movingToolStrip.Items.Add(changeDirectionButton)
End Sub
Public Sub changeDirectionButton_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles changeDirectionButton.Click
Dim item As ToolStripItem = CType(sender, ToolStripItem)
If item.TextDirection = ToolStripTextDirection.Vertical270 _
OrElse item.TextDirection = ToolStripTextDirection.Vertical90 Then
item.TextDirection = ToolStripTextDirection.Horizontal
movingToolStrip.Dock = System.Windows.Forms.DockStyle.Top
Else
item.TextDirection = ToolStripTextDirection.Vertical270
movingToolStrip.Dock = System.Windows.Forms.DockStyle.Left
End If
End Sub
注解
将 AutoSize 属性设置为 true
,使 ToolStripItem 调整其高度或宽度,具体取决于 的方向 ToolStrip,以确保 ToolStripItem 仅使用所需的空间量。
ToolStripItem如果 AutoSize 属性为 true
,则 具有最小大小。
AutoSize如果希望 ToolStripItem 小于系统定义的最小大小或将 大小设置为ToolStripItem零,请将 属性false
设置为 。