[英]How do I right align controls in a StatusStrip?
I am trying to right align a control in a StatusStrip
.我正在尝试右对齐
StatusStrip
的控件。 How can I do that?我怎样才能做到这一点?
I don't see a property to set on ToolStripItem
controls that specifies their physical alignment on the parent StatusStrip
.我没有看到要在
ToolStripItem
控件上设置的属性,该属性指定了它们在父StatusStrip
上的物理对齐方式。
How do I get Messages drop down to be right aligned? 如何让消息下拉以正确对齐? http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90
http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90
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
.您可以使用
ToolStripLabel
通过将Text
属性设置为string.Empty
并将Spring
属性设置为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
的右侧。
For me it took two simple steps:对我来说,它只需要两个简单的步骤:
MyRightIntendedToolStripItem.Alignment
to Right
MyRightIntendedToolStripItem.Alignment
设置为Right
MyStatusStrip.LayoutStyle
to HorizontalStackWithOverflow
MyStatusStrip.LayoutStyle
设置为HorizontalStackWithOverflow
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.
一致,因为 Messages 在您期望它的左侧右侧有一个插图。 A bit like the mspaint shot found on the MSDN page for StatusBars
有点像在MSDN 页面上为 StatusBars找到的 mspaint 截图
I like the creative appreach though :D我喜欢创造性的方法:D
You can display the Button
at the end of the StatusStrip
by using the logic below.您可以使用以下逻辑在
StatusStrip
的末尾显示Button
。
ToolstripLabel
to the StatusStrip
ToolstripLabel
到StatusStrip
string.Empty
string.Empty
Padding
for the ToolstripLabel
ToolstripLabel
设置Padding
For example:例如:
this.toolStripStatusLabel1.Padding = new Padding((int)(this.Size.Width - 75), 0, 0, 0);
保留工具条标签,将 Spring 属性设置为 true 并在底部左对齐标签文本
I found that you can set the StatusStrip Layout to HorizontalStackWithOverflow.我发现您可以将 StatusStrip 布局设置为 HorizontalStackWithOverflow。 Then, for each control on the StatusStrip that you want on the right side, set the control Alignment to Right.
然后,对于需要在右侧的 StatusStrip 上的每个控件,将控件对齐设置为右。
I like this better since you don't need any extra or dummy controls to align.我更喜欢这个,因为你不需要任何额外的或虚拟的控件来对齐。
如果将状态条标签控件的 Spring 属性设置为 true,则该标签将占用 StatusStrip 中其他控件未使用的任何空间。
I find a general way to set a control's location in StatusStrip
. 我找到了在
StatusStrip
设置控件位置的一般方法。 You can display the Button at any position in the StatusStrip
by using the steps below. 您可以使用以下步骤在
StatusStrip
中的任何位置显示按钮。
Set text as a suitable amount of space like 将文本设置为适当的空间,例如
toolStripStatusLabel1.Text = " ";
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. 如果布局不是您想要的布局,请转到步骤2更改
toolStripStatusLabel1.Text
的空间量,否则工作已经完成。
将 RightToLeft 工具条属性设置为 True。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.