当表单有滚动条时,控件位置是否相对于表单的可见区域? [英] Is control location relative to visible area of form when form has scroll bar?

查看:25
本文介绍了当表单有滚动条时,控件位置是否相对于表单的可见区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态创建一组控件的 VB.NET 表单.如果窗体上有太多控件要查看,窗体将显示滚动条.(这是一个自动滚动表单.)

I have a VB.NET form that dynamically creates a set of controls. If there are too many controls to view on the form, the form will show a scroll bar. (It is an autoscroll form.)

用户可以向下滚动并单击一个按钮,这会导致表单发生巨大变化.它会根据用户输入销毁所有控件并绘制新控件.

The user can scroll down and click a button which causes the form to change dramatically. It destroys all controls and draws new ones based on user input.

我注意到,如果用户滚动到表单底部并单击按钮,当我销毁和创建新控件时,它们不会位于我想要的位置.似乎将它们相对于表单的可见部分而不是顶部的顶部放置.

I've noticed that if the user is scrolled to the bottom of the form and click the button, when I destroy and create new controls they aren't located where I want them. It seems to put them relative to the visible portion of the form rather than the top of the top.

示例:

 checkbox1.top = 50
 checkbox1.left = 15

如果滚动条一直在底部,则复选框应放置在表单可见部分的上方.相反,它是在距离我能看到的顶部 50 像素处绘制的.

If the scrollbar is all the way at the bottom, the checkbox should be placed above the visible part of the form. Instead, it is drawn 50 pixels from the top of what I can see.

请帮忙.如何让它将控件放置在绝对位置,而不是相对于滚动条的当前位置?

Please help. How do I make it place the control at an absolute location, rather than being relative to the current position of the scrollbar?

推荐答案

你必须补偿容器控件的滚动位置.

You have to compensate for the scroll position of the container control.

如果是面板,那么它看起来像这样:

If a panel, then it would look like this:

checkbox1.Top = Panel1.AutoScrollPosition.Y + 50

或者,您可以只使用 FlowLayoutPanel 控件,它会为您处理控件的放置.

Alternatively, you could just use a FlowLayoutPanel control, which would handle the placement of the controls for you.

这篇关于当表单有滚动条时,控件位置是否相对于表单的可见区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆