将 ToolStripProgressBar 锚定到 StatusBar 右侧 (StatusStrip)

发布于 2024-08-07 20:48:11 字数 923 浏览 5 评论 0原文

我有一个带有状态栏的表单,其中有 2 个 ToolStripStatusLabel,后跟一个 ToolStripProgressBar。我希望进度条始终锚定在状态栏的右侧 - 因此当窗口大小/最大化时,它应该自动移动/重新粉刷。

我认为这就像将第一个(左对齐)ToolStripStatusLabelSpring 属性设置为 true 一样简单,因此当表单大小调整/增加时,并且有如果有更多可用空间,第一个 ToolStripStatusLabel 将填充该空间并自动将 ToolStripProgressBar 推到右侧。

但这不仅没有达到我想要的效果 - 第一个 ToolStripStatusLabel 实际上覆盖第二个 StatusLabelProgressBar,基本上占据了整个状态栏。 所有 ToolStrip 控件都没有 Anchor,甚至没有 MinSize。

那么我该如何:

  1. ToolStripProgressBar 锚定到 StatusBar(StatusStrip) 的右侧
  2. 混合一些固定大小项目(例如 ToolStripStatusLabel2ToolStripProgressBar),其大小可变的 ToolStripStatusLabel1 在有额外空间时会增大?

预先感谢您的时间和帮助!

〜即时通讯

I have a form with a statusbar that has 2 ToolStripStatusLabels 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 :

  1. Anchor the ToolStripProgressBar to right of StatusBar(StatusStrip)
  2. Mix some fixed size items (e.g the ToolStripStatusLabel2 and ToolStripProgressBar) with a variably sized ToolStripStatusLabel1 that grows when there is extra space?

Thanks in advance for your time and help !

~IM

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

流云如水 2024-08-14 20:48:12

有一个简单的解决方案。制作一个假的 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.

夜还是长夜 2024-08-14 20:48:12
  1. 将 StatusStrip、LayoutStyle 属性设置为 Horizo​​ntalStackWithOverflow。
  2. 将您想要位于右侧的控件的“对齐方式”设置为“右”。
  1. Set the StatusStrip, LayoutStyle property to HorizontalStackWithOverflow.
  2. Set the control Alignment to Right for the control you want to be to the right.
亽野灬性zι浪 2024-08-14 20:48:12

对于所有可能感兴趣的人.. 锚点属性是可用的,尽管仅在代码中(不在设计器中)...但无论如何,它不起作用.. 我在 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

暮凉 2024-08-14 20:48:12

首先将 AutoSize 更改为 false

toolStripProgressBar.AutoSize = false;

然后订阅 statusStrip 的尺寸更改事件

statusStrip1.SizeChanged += statusStrip1_SizeChanged;

最后在事件处理程序中更改栏的宽度

private void statusStrip1_SizeChanged(object sender, EventArgs e)
{
   toolStripProgressBar.Width = statusStrip1.Width - 95;
}

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

private void statusStrip1_SizeChanged(object sender, EventArgs e)
{
   toolStripProgressBar.Width = statusStrip1.Width - 95;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文