日期:2014-05-18  浏览次数:20793 次

c# ToolStrip 的ReSize问题
在ToolStrip 控件内放内个按钮和一个ToolStripComboBox
然后写ToolStrip 的ReSize属性,每个ToolStripComboBox的宽度等于ToolStrip 的宽度减按钮再减一定的数值
当ToolStrip 的宽度发生变化时ToolStripComboBox会自动改变大小,但是我发现一个问题
如果一次调整ToolStrip 的宽度只要右边界超过ToolStripComboBox的右边界这个ToolStripComboBox就会隐藏,然后右边出现一个下三角。
当点击这个下三角时ToolStripComboBox又会出现,而且尺寸已经调整过。
我想应该是ToolStrip 先隐藏了控件,然后再调整这个组件导致。
如何能让系统先执行RESIZE然后再判断是否应该隐藏一些控件。
或者其它方法能解决这个问题。

------解决方案--------------------
//改变地址栏长度
private void toolStrip1_SizeChanged(object sender, EventArgs e)
{
int allWidth = this.toolBrowser.Width;
int widths = 0;
foreach (ToolStripItem item in this.toolBrowser.Items)
{
if (item.Name == this.toolBrowserUrl.Name)
continue;
widths += item.Width;
}
this.toolBrowserUrl.Width = allWidth - widths - 12;
}
------解决方案--------------------
探讨
//改变地址栏长度
private void toolStrip1_SizeChanged(object sender, EventArgs e)
{
int allWidth = this.toolBrowser.Width;
int widths = 0;
foreach (ToolStripItem item in this.toolBrowser.Items)
{
if (item.Name == this.toolBrowserUrl.Name)
continue;
widths +…