将 ToolStripProgressBar 锚定到 StatusBar 右侧 (StatusStrip)
我有一个带有状态栏的表单,其中有 2 个 ToolStripStatusLabel
,后跟一个 ToolStripProgressBar
。我希望进度条始终锚定在状态栏的右侧 - 因此当窗口大小/最大化时,它应该自动移动/重新粉刷。
我认为这就像将第一个(左对齐)ToolStripStatusLabel
的 Spring
属性设置为 true 一样简单,因此当表单大小调整/增加时,并且有如果有更多可用空间,第一个 ToolStripStatusLabel
将填充该空间并自动将 ToolStripProgressBar
推到右侧。
但这不仅没有达到我想要的效果 - 第一个 ToolStripStatusLabel
实际上覆盖第二个 StatusLabel
和 ProgressBar,基本上占据了整个状态栏。 所有 ToolStrip 控件都没有 Anchor,甚至没有 MinSize。
那么我该如何:
- 将
ToolStripProgressBar
锚定到 StatusBar(StatusStrip) 的右侧 - 混合一些固定大小项目(例如
ToolStripStatusLabel2
和ToolStripProgressBar
),其大小可变的ToolStripStatusLabel1
在有额外空间时会增大?
预先感谢您的时间和帮助!
〜即时通讯
I have a form with a statusbar that has 2 ToolStripStatusLabel
s followed by a ToolStripProgressBar
. I want the progressbar to be always anchored to the right of the statusbar - so when the window is resized/maximized, it should automatically move/repaint.
I thought this would be as simple as setting the 1st (left aligned) ToolStripStatusLabel
's Spring
property to true, so when the form is resized/increased in size, and there is more space available, the 1st ToolStripStatusLabel
would fill up that space and automatically push the ToolStripProgressBar
to the Right.
But not only does that not do what I want - the 1st ToolStripStatusLabel
actually covers up both the 2nd StatusLabel
and the ProgressBar
, basically occupying the whole statusbar.
None of the ToolStrip controls have Anchor or even a MinSize.
SO how do I :
- Anchor the
ToolStripProgressBar
to right of StatusBar(StatusStrip) - Mix some fixed size items (e.g the
ToolStripStatusLabel2
andToolStripProgressBar
) with a variably sizedToolStripStatusLabel1
that grows when there is extra space?
Thanks in advance for your time and help !
~IM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一个简单的解决方案。制作一个假的 ToolStripStatusLabel,清空 .Text 并设置 .Spring = true;
之后,添加您的 ToolStripProgressBar。确保顺序首先是标签,然后是进度条。
There's a simple solution. Make one fake ToolStripStatusLabel, empty the .Text and set .Spring = true;
After that, add your ToolStripProgressBar. Make sure the order is label first, then progressbar.
对于所有可能感兴趣的人.. 锚点属性是可用的,尽管仅在代码中(不在设计器中)...但无论如何,它不起作用.. 我在 Connect 中留下了一个 BUG 并得到了带有消息的通用 WillNotFix似乎表明他们只会考虑对其进行重大修改。
由于某种原因,“Spring”属性似乎不稳定。在我的极其简单的示例中,它正在工作,但在其他一些示例中,我做了一些自定义绘画(但在 MDIPArent 的子窗体中,后者具有 ht eStatusBar)它不是。在这些情况下,仍然有一个简单的解决方法 - 在 MDIParent 表单(具有状态栏)的 ReSize 事件中,更改 StatusLabel 的大小,使其以与宽度更改相同的比例变大,因此它会推动 ProgressBar到状态栏的右边缘
For all who may be interested.. Anchor property is available, although in Code only (not in designer) ...but in any case, it DOES NOT work.. I left a BUG in Connect and got the generic WillNotFix with the Message seeming to indicate they'll consider it only for a major revision.
For some reason the "Spring" property seems to be erratic.. In my ultra-simpistic examples it is working, but in some others where I do some custom painting (but in Child Forms in a MDIPArent, with the latter having ht eStatusBar) it is not. In those cases, there's still a simple workaround though - in the ReSize event of the MDIParent Form (that has the statusbar) change the size of the StatusLabel to make it bigger in the same proprtion as th width-change, so it pushes the ProgressBar to the right edge of the StatusBar
首先将 AutoSize 更改为 false
toolStripProgressBar.AutoSize = false;
然后订阅 statusStrip 的尺寸更改事件
statusStrip1.SizeChanged += statusStrip1_SizeChanged;
最后在事件处理程序中更改栏的宽度
First change AutoSize to false
toolStripProgressBar.AutoSize = false;
Then subscribe statusStrip's size changed event
statusStrip1.SizeChanged += statusStrip1_SizeChanged;
Finally change the bar's width in the event handler