【发布时间】:2012-01-05 13:43:07
【问题描述】:
我有两个相关的问题出现在以下情况。
我有一个包含一些面板的 winforms 窗口。在其中一些面板中,有许多(自定义)wpf 用户控件。
1
如果我在 elementhost 上检查 .Visible,它总是返回 true。即使我可以看到它不可见。
2
如果我检查 .Height,它总是会给我相同的尺寸。即使控件本身显示可变数量的事物并相应地更改大小(通过 Visibility.collaps);
我怎样才能得到正确的值?
编辑:添加代码
Okey 现在我要疯了。 如果我在我的代码中添加一些消息框来检查上述代码执行的时间和顺序。当我这样做时,一切正常!但是一旦我删除消息框,它就会反转效果。不是在需要时变大,而是变小,反之亦然.... wtf wpf!
private Size bereken_panel(Panel P)
{
Size Sz = new Size();
int tmp_H = 42;
foreach (Control SC in P.Controls)
{
if (SC is SplitContainer)
{
if (SC.Visible)
{
tmp_H += SC.Height;
}
}
else if (SC is System.Windows.Forms.Integration.ElementHost)
{
if ((SC as System.Windows.Forms.Integration.ElementHost).Child.Visibility == System.Windows.Visibility.Visible)
{
tmp_H += (int)(SC as System.Windows.Forms.Integration.ElementHost).Child.RenderSize.Height;
}
}
}
// tmp_H = 42 + n_showed * 25;
if (tmp_H < 65)
{
tmp_H = 65;
}
Sz.Height = tmp_H;
Sz.Width = 432;
return Sz;
}
所以这是经过一些额外的修改 澄清 TopLeft 点在哪里。
int p_x_links = panel1.Width / 2 - 436;
int p_x_rechts = panel1.Width / 2 + 4;
//links
p_contact_gegevens.Size = bereken_panel(p_contact_gegevens);
p_telnrs.Location = new Point(p_x_links, p_contact_gegevens.Size.Height + p_contact_gegevens.Location.Y + 8);
p_telnrs.Size = bereken_panel(p_telnrs);
p_bezoekadres.Location = new Point(p_x_links, p_telnrs.Size.Height + p_telnrs.Location.Y + 8);
p_bezoekadres.Size = bereken_panel(p_bezoekadres);
//rechts
p_administratie.Size = bereken_panel(p_administratie);
p_postadres.Location = new Point(p_x_rechts, p_administratie.Size.Height + p_administratie.Location.Y + 8);
p_postadres.Size = bereken_panel(p_postadres);
【问题讨论】:
-
能否提供代码部分,哪里有问题?