ToolStripComboBox 放置在 ToolStripButton 后面,后面是另一个右对齐的工具条组合框。如何最好地将 ToolStripComboBox 设置为始终调整其长度以填充前后 ToolStripButton 之间的所有可用空间?
过去,我曾经处理父级调整大小事件,根据相邻元素坐标计算要设置的新长度并设置新大小。但现在,当我开发一个新的应用程序时,我想知道是否有更好的方法。
我使用以下方法取得了巨大成功:
private void toolStrip1_Layout(System.Object sender, System.Windows.Forms.LayoutEventArgs e)
{
int width = toolStrip1.DisplayRectangle.Width;
foreach (ToolStripItem tsi in toolStrip1.Items) {
if (!(tsi == toolStripComboBox1)) {
width -= tsi.Width;
width -= tsi.Margin.Horizontal;
}
}
toolStripComboBox1.Width = Math.Max(0, width - toolStripComboBox1.Margin.Horizontal);
}
上面的代码没有遇到控制消失问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)