如何制作一个ToolStripComboBox来填充ToolStrip上的所有可用空间? [英] How to make a ToolStripComboBox to fill all the space available on a ToolStrip?

查看:245
本文介绍了如何制作一个ToolStripComboBox来填充ToolStrip上的所有可用空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个ToolStripComboBox放置在一个ToolStripButton之后,并由另一个右对齐的对象跟随.如何最好地设置ToolStripComboBox以始终调整其长度,以填补前面和后面的ToolStripButton之间的所有可用空间?

A ToolStripComboBox is placed after a ToolStripButton and is folowed by another one, which is right-aligned. How do I best set up the ToolStripComboBox to always adjust its length to fill all the space available between the preceeding and the folowing ToolStripButtons?

过去,我曾经处理过父级调整大小事件,根据相邻元素的坐标计算要设置的新长度并设置新大小.但是现在,当我在开发一个新的应用程序时,我想知道是否还有更好的方法.

In past I used to handle a parent resize event, calculate the new length to set based on neighboring elements coordinates and setting the new size. But now, as I am developing a new application, I wonder if there is no better way.

推荐答案

没有自动布局选项.但是,您可以通过实现ToolStrip.Resize事件轻松地做到这一点.效果很好:

There's no automatic layout option for this. But you can easily do it by implementing the ToolStrip.Resize event. This worked well:

    private void toolStrip1_Resize(object sender, EventArgs e) {
        toolStripComboBox1.Width = toolStripComboBox2.Bounds.Left - toolStripButton1.Bounds.Right - 4;
    }
    protected override void OnLoad(EventArgs e) {
        toolStrip1_Resize(this, e);
    }

请确保将TSCB的AutoResize属性设置为False,否则它将无法正常工作.

Be sure to set the TSCB's AutoResize property to False or it won't work.

这篇关于如何制作一个ToolStripComboBox来填充ToolStrip上的所有可用空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆