用户控件无法正确适应屏幕

发布于 2024-08-28 22:12:02 字数 228 浏览 1 评论 0原文

我的应用程序有几个控件。就像在一个屏幕中,左侧有 TreeView,中间有分页的 GridView,右侧有 4 个按钮。当窗体处于最大化状态时,控件会正确显示,但如果我将其最小化,控件将无法正确显示在屏幕上。

我尝试了不同的技巧,例如表格布局......在 dat 中我添加了面板等......

但我无法解决问题。

如何创建这种类型的屏幕,无论其大小如何,都适合我的窗口?

谢谢

My application has several controls. Like in one screen has TreeView on left side, GridView with paging in the middle and 4 buttons at right side. The controls properly appear when the form is in a maximized state, but if I minimize it the controls do not properly fit on the screen.

I tried with different different tricks like table layout.. in dat I added a panel, etc...

But I could not solve the problem.

How can I create such type of screens which fits independently of size of my window?

Thanks

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

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

发布评论

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

评论(1

分開簡單 2024-09-04 22:12:02

不久前我也遇到了同样的问题。就我而言,我在 SplitContainer 内的 GroupBox 中有一个 Button 和一个 ListView,而 SplitContainer 位于 TabControl 上的 UserControl 内。我想要右上角的按钮定位并锚定,而 ListView 占据了剩余的空间,所以我无法停靠它。相反,它固定在所有四个地方。

就我而言,我的按钮和列表视图在设计器中工作和行为正确,但在我正在运行的应用程序中,按钮位于右侧较远的位置,并且 ListView 大小的宽度也太大。

对于第一个错误修复,我做了一些迭代,将设计器中的按钮定位在左侧一点,检查它的运行模式,根据我上次运行的印象重新对齐设计器中的按钮。

所以我让它工作并重新开始我必须在我的应用程序中做的其他事情。一段时间后,我收到了一个新功能请求,并且需要在这个混乱的东西中添加另一个按钮。这次我在新的用户控件上完全重建了 gui 元素,只是为了看看问题是否再次出现。令我惊讶的是,这个 gui 模拟的行为正如预期的那样。

在我的代码中,我没有更改位置、大小、锚点、停靠点等。因此,问题必须出在设计者创建的 InitializeComponents() 代码中。

我从两个版本的差异开始,看不到任何大的差异(有很多差异,但只有大小、位置或名称等次要差异)。所以我开始将我疯狂的用户控件中的代码放入模拟中,并在我的应用程序中运行模拟。经过几次复制后,问题也出现在我的模拟中,所以我找到了问题的根本原因。

您认为哪个属性导致了疯狂的行为?
这是我的 SplitContainerMinimumSize

因此,要真正找到问题的根本原因,您应该从一个空的用户控件(或表单)开始,然后将所有元素以所需的行为(大小、位置、锚点、停靠)放置在其上。

而已!

然后测试这个模拟是否按照您想要的方式运行,如果没有,请在此处发布此代码并告诉我们您期望看到什么。

I had the same problem a while ago. In my case i had a Button and a ListView within a GroupBox that was inside a SplitContainer, which was within a UserControl on a TabControl. I wanted the button on the top right located and anchored and the ListView took the space leftover, so i couldn't dock it. Instead it was anchored in all four places.

In my case my button and the listview are worked and behaved correctly in the designer, but in my running app the button was positioned to far on the right and the ListView size had also a too much width.

For a first bugfix i did some iterations about positioning the button in the designer a little more to the left, check it running mode, re-align the button in designer from the impression i had in the last run.

So i got it to work and started over with some other thing i had to do in my app. After a while i got a new feature request and needed another button within this messy thing. This time i did a complete rebuild of the gui elements on a new usercontrol, just to see if the problem reappears. To my amazement this gui mock just behaved as expected.

Within my code i didn't anything about changing the location, size, anchors, docks, etc. So the problem had to be within the InitializeComponents() code created by the designer.

I started with a diff of both versions and couldn't see any big differences (there were a lot of them, but only minors like size, location or name). So i started to put code from my crazy usercontrol into the mock and running the mock in my app. After several copies the problem also appears in my mock, so i got the root cause of the problem.

What do you think, which property leaded to the crazy behaviour?
It was the MinimumSize of my SplitContainer!

So to get really the root cause of your problem you should start over with an empty UserControl (or Form) and just place all the elements on it with the desired behaviour (size, location, anchor, dock).

Nothing more!

Then test if this mock behaves the way you want and if not, post this code here and tell us what you expected to see.

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