C# Windows 窗体,选项卡上的控件

发布于 2024-08-04 15:49:33 字数 364 浏览 8 评论 0原文

我的表单上有一个选项卡控件,在每个选项卡上都有一个控件,每个控件都很相似,即它们每个都有一个表格和几个按钮,每个控件都设置为 Dock Fill

当我在设计视图中查看它们的控件时,有些奇怪的东西正在发生,第一个可见的选项卡的控件按照您的预期放置,一切都很好,但第二个和第三个选项卡的每个控件都偏离中心,与选项卡的边缘重叠。

我尝试过将不同的控件放置在不同的选项卡上,如果控件位于第一个选项卡上,它看起来很好,如果它位于任何其他选项卡上,有时会显得很奇怪。

真正的大问题是,这似乎也出现在运行时,但只是有时。

我已经检查了控件和选项卡的属性,但似乎都是相同的。

任何建议将不胜感激。

亲切的问候

MeeM

I have a tabcontrol on my form, on each tab I have a control, each of these controls are similar i.e. they each have a table and a couple buttons and each control is set to Dock Fill

When I view them contols in design view something weird is happening, the first tab that is viewable has it controls placed as you would expect and all is fine, but the second and third tab each the controls appear off centre, overlapping the edges of the tab.

I have experimented with placing different controls on different tabs and it appears that if a control is on the first tab it appears fine, if it is on any other it sometimes appears weird.

The really big problem is that this seems to be appearing at run-time as well, but only sometimes.

I've checked the properties of the controls and the tabs but all seems to be the same.

Any advice would be much appreciated.

Kind regards

MeeM

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

晨曦÷微暖 2024-08-11 15:49:33

对我来说这似乎是一个错误,请确保您拥有 Visual Studio 的所有最新更新。

Seems like a bug to me, make sure you have all the latest updates for Visual Studio.

遇到 2024-08-11 15:49:33

这是您放置在选项卡上的用户控件吗?如果是这样,我将检查用户控件和用户控件内的子控件的所有布局属性。我以前遇到过这个问题,但我不记得我做了什么来解决它。

Is this a UserControl that you are placing on a tab? If so, I would check all the layout properties on the user control and the child controls inside the user control. I have had this problem before, but I can't remember off had what I did to fix it.

多彩岁月 2024-08-11 15:49:33

试试这个:

  1. 首先要验证控件的 z 顺序是否正确。为此,打开“文档大纲”窗口(“查看”->“其他窗口”->“文档大纲”)并一一目视检查每个控件的顺序。当设置控件的停靠属性时,控件的 z 顺序会反向应用;也就是说:文档大纲中显示的第一个子控件的停靠优先级高于文档大纲窗口中较低级别的子控件。

  2. 验证同一父级的 2 个子控件(在您的情况下为 tabControl)没有 DockStyle.Fill。作为一种良好的对接实践,只有一个子控件应将其对接设置为 Fill。如果您遇到这种情况,很可能重新考虑您的布局流程将允许您更改它并且只有一个带有填充。其他停靠样式(右、左、上、下)可以在多个子控件中使用,并且它们永远不会引起任何问题。只有 Fill 是有问题的。

  3. 如果 1 或 2 解决了您的问题,我的建议是完全避免对接并使用锚定。使用控件的 Anchor 属性,您基本上可以获得非常相似的结果。我实际上更喜欢这种方法,因为它有点类似于 WPF 锚定。

  4. 如果 1、2 而不是 3 可以解决您的问题。发布带有文档大纲的图像,我将在此处重新创建它,修复它并在此处发布解决方案。

希望有帮助!

Try this:

  1. First thing is to verify the z-order of your controls is correct. For that open your Document Outline window (View->Other Windows->Document Outline) and visually check for the order of each control one by one. When setting the docking properties of controls the z-order of the controls is applied in reverse; that is: the first child control shown in the document outline has docking precedence over those at the same level lower in the document outline window.

  2. Verify that no 2 child controls of the same parent (in your case the tabControl) have the DockStyle.Fill. As a good practice with docking, only one of the child controls should have its docking set to Fill. If you have this case it is most likely rethinking your layout flow will allow you to change it and have only one with Fill. The other docking styles (right, left, top, bottom) can be used in more than one child control and they'll never cause any problems. Only Fill is the problematic one.

  3. If 1 nor 2 solved your problem, my advice if to avoid docking altogether and use Anchoring instead. You can essentially get very similar results using the Anchor property of the controls. I actually like this approach more, since is kinda similar to WPF anchoring.

  4. If 1, 2 not 3 solve your problem. Post an image with your document outline and I'll recreate it here, fix it and post the solution here.

Hope it helped!

浅忆 2024-08-11 15:49:33

我假设这些是我们正在讨论的用户控件。自从将用户控件添加到选项卡中后,您是否更改了控件(类)本身的布局?如果是这样,它们将不会自动更新为新值(对于 Dock、宽度、高度等)。

I assume that these are user controls we are talking about. Have you changed the layout of the control (class) itself since you added the user controls into your tabs? If so, they will not automatically update with the new value (for Dock, width, height, etc.).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文