可以自动调整自身大小的工具条
我正在使用这个很好的代码,顺便说一句,如果您知道有更好的方法来完成此任务,我真的很感激让我们知道。 所以这里是可以浮动的工具栏:
http://en .csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Floating_ToolStrips
很好,但是如果我这个工具栏上只有 4 个按钮怎么办,当我让它浮动时,它的大小仍然与原来相同之前停靠在表单上,但我希望它可以调整自身大小,并且只要需要在其上显示按钮即可。
I am using this nice code which by the way if you are aware of any better way to accomplish this, I really appreciate letting us know .
so here is the Toolbar that can float :
http://en.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Floating_ToolStrips
good, but what if I only have 4 buttons on this toolbar, when I make it float it is still the same size as it was docked to the form before but I wish it could resize itself and just be as long as it needs to be to show its buttons on it .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将各个工具条项目的宽度相加,并将其用作表单的宽度。
将其替换
为:
You can add up the widths of the individual toolstrip items and use that as the width of your form.
Replace this:
with this:
PreferredSize 帮我解决了这个问题。我没想到会在 ToolStip 上工作,但它确实如此,至少在 .Net 4.5 上是这样。
我仍然必须添加一个固定的数字来说明一些我不确定它们来自哪里的像素。
PreferredSize did the trick for me. I didn't expect to work on a ToolStip but it does, at least on .Net 4.5.
I still had to add a fixed number to account for a few pixels that I'm not sure where they are coming from.