C# 如何正确对齐 StatusStrip 中的控件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/509508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I right align controls in a StatusStrip?
提问by Eric Schoonover
I am trying to right align a control in a StatusStrip
. How can I do that?
我正在尝试在StatusStrip
. 我怎样才能做到这一点?
I don't see a property to set on ToolStripItem
controls that specifies their physical alignment on the parent StatusStrip
.
我没有看到要在ToolStripItem
控件上设置的属性来指定它们在 parent 上的物理对齐方式StatusStrip
。
如何让消息下拉以正确对齐?http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90
采纳答案by Eric Schoonover
Found it via MSDN forums almost immediately after posting :)
发布后几乎立即通过 MSDN 论坛找到它:)
You can use a ToolStripLabel
to pseudo right align controls by setting the Text
property to string.Empty
and setting the Spring
property to true
. This will cause it to fill all of the available space and push all the controls to the right of the ToolStripLabel
over.
您可以使用ToolStripLabel
通过设置模拟右对齐控件Text
属性string.Empty
和设置Spring
属性true
。这将导致它填满所有可用空间并将所有控件推到右侧ToolStripLabel
。
回答by Martijn Laarman
As an added note this is due to the fact that in the Win32 API a cell is either fixed width or fills the remaining space -1
作为补充说明,这是因为在 Win32 API 中,单元格是固定宽度或填充剩余空间 -1
int statwidths[] = {100, -1};
SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");
If memory serves me correctly you can have only one fill cell (-1) per statusbar.
如果没记错的话,每个状态栏只能有一个填充单元格 (-1)。
You could also add a third middle cell and give this the fill property to get a more concistent looking StatusBar. Consistent because Messages has an inset to its left right where you'd expect it. A bit like the mspaint shot found on the MSDN page for StatusBars
您还可以添加第三个中间单元格并为其指定填充属性以获得外观更加一致的状态栏。一致,因为 Messages 在您期望它的左侧右侧有一个插图。有点像在MSDN 页面上为 StatusBars找到的 mspaint 截图
I like the creative appreach though :D
我喜欢创造性的方法:D
回答by Chandran R
You can display the Button
at the end of the StatusStrip
by using the logic below.
您可以使用以下逻辑Button
在 的末尾显示StatusStrip
。
- Add a
ToolstripLabel
to theStatusStrip
- Set text as
string.Empty
- Set
Padding
for theToolstripLabel
- 一个添加
ToolstripLabel
到StatusStrip
- 将文本设置为
string.Empty
- 设置
Padding
为ToolstripLabel
For example:
例如:
this.toolStripStatusLabel1.Padding = new Padding((int)(this.Size.Width - 75), 0, 0, 0);
回答by TravisHendrickson
Set the RightToLeft tool strip property to True.
将 RightToLeft 工具条属性设置为 True。
回答by Visakh V A
Keep a Toolstrip label , set Spring property as true and for label align text in BottomLeft
保留工具条标签,将 Spring 属性设置为 true 并在底部左对齐标签文本
回答by Alan Ackart
I find a general way to set a control's location in StatusStrip
.
You can display the Button at any position in the StatusStrip
by using the steps below.
我找到了一种在StatusStrip
. 您可以StatusStrip
使用以下步骤在 中的任何位置显示按钮。
- Add a ToolstripLabel to the StatusStrip
Set text as a suitable amount of space like
toolStripStatusLabel1.Text = " ";
If layout is not what you want, got to step 2 to change the amount of space in
toolStripStatusLabel1.Text
, else work has been done.
- 将工具条标签添加到状态条
将文本设置为合适的空间量,例如
toolStripStatusLabel1.Text =“ ”;
如果布局不是您想要的,请转到第 2 步以更改 中的空间量
toolStripStatusLabel1.Text
,否则工作已完成。
回答by VBobCat
For me it took two simple steps:
对我来说,它只需要两个简单的步骤:
- Set
MyRightIntendedToolStripItem.Alignment
toRight
- Set
MyStatusStrip.LayoutStyle
toHorizontalStackWithOverflow
- 设置
MyRightIntendedToolStripItem.Alignment
为Right
- 设置
MyStatusStrip.LayoutStyle
为HorizontalStackWithOverflow
回答by knightgambit
I found that you can set the StatusStrip Layout to HorizontalStackWithOverflow. Then, for each control on the StatusStrip that you want on the right side, set the control Alignment to Right.
我发现您可以将 StatusStrip 布局设置为 HorizontalStackWithOverflow。然后,对于需要在右侧的 StatusStrip 上的每个控件,将控件对齐设置为右。
I like this better since you don't need any extra or dummy controls to align.
我更喜欢这个,因为你不需要任何额外的或虚拟的控件来对齐。