问题描述
我有一个复杂的 Windows 窗体 GUI 程序,它有很多自动控件生成和操作.我需要做的一件事是将自定义 UserControl 添加到新安装的 TabPage.但是,当我的代码执行此操作时,我会得到自动调整大小的事件,导致格式变得难看.在不详细说明可能涉及的所有不同容器的情况下,基本问题是这样的:
I have a complex Windows Forms GUI program that has a lot of automated control generation and manipulation. One thing that I need to be able to do is add a custom UserControl to a newly instatiated TabPage. However, when my code does this I get automatic resizing events that cause the formatting to get ugly. Without detailing all of the different Containers that could possibly be involved, the basic issue is this:
在代码中的某个位置,我创建了一个新标签页:
At a certain point in the code I create a new tab page:
TabPage tempTabPage = new TabPage("A New Tab Page");
然后我将它设置为我希望它保持的特定大小:
Then I set it to a certain size that I want it to maintain:
tempTabPage.Width = 1008;
tempTabPage.Height = 621;
然后我将它添加到 TabControl:
Then I add it to a TabControl:
tabControl.TabPages.Add(tempTabPage);
然后我创建一个我希望出现在新添加的 TabPage 中的用户控件:
Then I create a user control that I want to appear in the newly added TabPage:
CustomView customView = new CustomView("A new custom control");
这就是问题所在.此时 tempTabPage 和 customView 的大小相同,没有填充或边距,它们是我想要的大小.我现在尝试将这个新的自定义 UserControl 添加到标签页,如下所示:
Here is where the problem comes in. At this point both the tempTabPage and the customView are the same size with no padding or margin and they are the size I want them to be. I now try to add this new custom UserControl to the tab page like this:
tempTabPage.Controls.Add(customView);
当调用 customView 时,它的子控件会被调整为更大,因此 customView 的某些部分被隐藏了.
When making this call the customView and it's children controls get resized to be larger and so parts of the customView are hidden.
谁能给我任何关于寻找什么或可能导致此类问题的方向?
Can anyone give me any direction on what to look for or what could be causing this kind of issue?
提前谢谢.
推荐答案
UserControl 的AutoScaleMode"属性应该设置为None".
The UserControl's "AutoScaleMode" property should be set to "None".
这篇关于将 .Net UserControl 添加到 TabPage 时出现大小调整问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!