SplitContainer - 当方向设置为水平时,是什么导致我遇到不一致的行为?

发布于 2024-09-28 16:30:50 字数 1176 浏览 4 评论 0原文

在一个新项目中从头开始,其中默认 Form1 表单的属性尚未更改,我在表单上放置一个 SplitContainer,并将其属性设置为:

锚点 - 顶部、左

停靠 - 填充

方向 - 垂直

然后我放置第二个 SplitContainer进入第一个 SplitContainer 的左侧面板(面板 1),并再次将其属性设置为上面的属性,但这次拆分器的方向设置为水平。

我现在将两个 CheckedListBox 放置在第二个 SplitContainer 的上部和下部面板(面板 1 和 2)中。两个 CheckedListBox 的属性均设置为:

Anchor - Top、Left

Dock - Fill

我现在将一个 TextBox 添加到第一个 SplitContainer 的右侧面板(面板 2),并将其属性设置为:

Anchor - Top、Left

Dock - Fill

多行 - True

当我编译并运行此应用程序时,构成我添加的第一个 SplitContainer 一部分的垂直拆分器的行为和工作方式与预期完全一致 - 所以没有问题。 然而,第二个 SplitContainer 中的水平方向拆分器始终显示不稳定的行为 - 拆分器本身的宽度随着其上下移动而变化。但是分流器宽度的这种增加或减少也与其移动的方向不一致 - 例如,在启动时将其从其初始位置向上移动一段距离可能会导致分流器比之前更薄进一步向上调整大小会导致其变厚。

当我移动拆分器时,下部 CheckedListBox 的底部边缘也会上下移动,并且与之前一样,此行为与拆分器移动的方向不一致。

为了避免将组件属性的更改从一个实验转移到另一个实验,我一直试图通过从头开始启动六个左右的新项目并尝试不同的事情来弄清楚发生了什么,包括对 Anchor、BorderStyle、Dock 的更改和 Margin 属性,但不幸的是我一无所知:-(

有没有人对这种不稳定的行为有类似的经历并且可以为我提供解决方案?我可能会忽略一些简单的东西,如果是这样的话那是什么?

感谢阅读。

编辑\更新 - 经过进一步的实验,我能够确定我遇到的不需要的行为在某种程度上与 CheckedListBoxes 有关 - 我用多行文本框替换了这两个文本框,其“Anchor”和“Dock”属性设置为“Top,Left”和“分别填充”,并且在运行应用程序时,不再出现不稳定的行为 - 垂直和水平分离器都正常工作。

Starting from scratch in a new project in which the properties of the default Form1 form have not been altered I drop a SplitContainer on the form and set its properties to:

Anchor - Top, Left

Dock - Fill

Orientation - Vertical

I then drop a second SplitContainer into the left-hand panel (panel 1) of the first SplitContainer and again set its properties to those above except this time the orientation of the splitter is set to horizontal.

I now place two CheckedListBoxes in both the upper and lower panels (panels 1 & 2) of the second SplitContainer. The properties of both CheckedListBoxes are set to:

Anchor - Top, Left

Dock - Fill

I now add a TextBox to the right-hand panel (panel 2) of the first SplitContainer and set its properties to:

Anchor - Top, Left

Dock - Fill

Multi-Line - True

When I compile and run this application the vertical splitter which forms part of the first SplitContainer I added behaves and works exactly as expected - so no problem there.
However, the horizontally oriented splitter in the second SplitContainer consistently displays erratic behaviour - the width of the splitter itself changes as it is moved up and down. But this increase or decrease in the width of the splitter is also not consistent with the direction in which it was moved - for example moving it up some distance from its initial position at startup may result in the splitter being thinner than what it was previously while a further resizing upwards results in it being thicker.

The bottom edge of the lower CheckedListBox also moves up and down when I move the splitter and as before this behaviour is not consistent with the direction in which the splitter is moved.

To avoid carrying over changes to a component's properties from one experiment to another I have been trying to figure out what is going on by starting half a dozen or so new projects from scratch and trying out different things including changes to the Anchor, BorderStyle, Dock, and Margin properties, but unfortunately I am none the wiser : -(

Has anyone had similar experience of this erratic behaviour and can offer me a solution? I might be overlooking something simple, if so what is it?

Thanks for reading.

Edit \ Update -
Upon further experimentation I was able to determine that the unwanted behaviour I am experiencing is related somehow to the CheckedListBoxes - I replaced both with multi-line textboxes whose properties of "Anchor" and "Dock" were set to "Top, Left" and "Fill" respectively and upon running the app the erratic behaviour no longer occurs - both the vertical and horizontal splitters are working correctly.

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

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

发布评论

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

评论(1

失眠症患者 2024-10-05 16:30:50

将列表框的 IntegralHeight 属性设置为 False,以便允许它们调整自身大小以适合面板。

Set the IntegralHeight property of the list boxes to False so that they are allowed to size themselves to fit the panel.

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