.NET TabControl 容器锚定问题
我在使用 c# Winforms 时遇到了一个奇怪的问题(诚然没有尝试过 VB.NET),其中我在页面上有一个 TabControl 和 4 个 TabPage。
在最小化表单后显示表单时,我有一些身份验证逻辑来显示/隐藏这些选项卡页面。这种“隐藏”逻辑本质上会删除选项卡,并在表单通过身份验证时重新插入它们。
因此,首先将应用程序最小化。我恢复它,但身份验证失败,因此选项卡被删除。我再次最小化应用程序,恢复窗口,通过身份验证并插入选项卡。然而,页面内锚定到相对侧的控件(因此左侧、右侧、顶部、底部以允许它们拉伸)似乎已损坏。顶部/左侧位置没问题,但相反的位置似乎超出了可见页面!
我猜这都与页面的删除和添加有关,但是以前有人见过这个并知道为什么会发生这种情况吗? (更重要的是知道解决方法):)
请注意,我隐藏/显示选项卡的代码使用如下函数: -
private void TabControlPageVisible(TabPage page, Boolean show)
{
if (show)
{
if (!tabControlMain.TabPages.Contains(page))
{
tabControlMain.TabPages.Insert(0, page);
page.ResumeLayout();
}
}
else
{
if (tabControlMain.TabPages.Contains(page))
{
page.SuspendLayout();
tabControlMain.TabPages.Remove(page);
}
}
}
干杯! :)
I'm having a strang problem with c# Winforms (not tried VB.NET admittingly) whereby I have a TabControl on a page, and 4 TabPages.
I have some authentication logic to show/hide these TabPages when showing the form after it's been minimised. This "hiding" logic will essentially remove the tabs, and re-insert them when the form authenticates.
So, First the application is minimised. I restore it, fail my authentication and so the tabs are removed. I minimise the application again, restore the window, pass the authentication and the tabs are inserted. However, the controls within the pages that are anchored to opposite sides (so left, right and top, bottom to allow them to stretch) appear to have broken. The top/left positions are ok, but the opposite position appears to have stretched off the visible page!
I'm guessing this is all related to the removal and additions of pages, but has anyone seen this before and know why this happens?? (and more importantly know a work around) :)
Just to note, my code to hide/show the tabs uses a function as follows: -
private void TabControlPageVisible(TabPage page, Boolean show)
{
if (show)
{
if (!tabControlMain.TabPages.Contains(page))
{
tabControlMain.TabPages.Insert(0, page);
page.ResumeLayout();
}
}
else
{
if (tabControlMain.TabPages.Contains(page))
{
page.SuspendLayout();
tabControlMain.TabPages.Remove(page);
}
}
}
Cheers! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是在每个页面上使用布局方法还是只是定位控件?一个(麻烦的)解决方案是存储每个控件的位置。更好的主意是使用布局。
are you using a layout method on each page or you're just positioning the controls? a (troublesome) solution is to store the position of each control. a much better idea would be to use a layout.