如何使表单的某个部分可滚动? [英] How can I make a certain part of my form scrollable?

查看:21
本文介绍了如何使表单的某个部分可滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 vb6 编写一个程序,它要求我能够向右滚动屏幕的某个区域.它仅由线条和图片框组成,有没有办法只滚动该区域?谢谢!

I'm making a program in vb6 that requires me to be able to scroll a certain area of the screen to the right. It consists solely of lines and picture boxes, is there a way to only scroll that area? Thanks!

推荐答案

您可以利用一些可视化控件可以充当其他可视化控件的容器这一事实.

You can take advantage from the fact that some visual controls can act as container of other visual controls.

举个例子:

在 VBIDE 中,将 Frame 放在 VB 窗体上.然后 - 在这个 Frame 中放置一个 PictureBox.注意PictureBox应该完全包含在这个Frame中.

In the VBIDE, place a Frame over a VB Form. Then - inside this Frame place a PictureBox. Pay attention that the PictureBox shall be fully contained inside this Frame.

现在,如果你在Form周围拖动Frame,你会看到里面的PictureBox一起移动,同时保持容器Frame内部的位置,即保持原来的顶部&相对于容器控件的左坐标.

Now, if you drag the Frame around the Form, you will see that the PictureBox inside is moving together, while keeping the position inside the container Frame, i.e. it will keep the original top & left coordinates relative to the container control.

要找出哪些视觉控件具有此功能,只需重试测试即可.例如,您将看到 Label 不能充当容器.

To find out which visual controls have this capability, simply retry the test. You will see, for example, that a Label can't act as a container.

也就是说,您需要以下内容:

That said, you need following:

  • 作为容器(视口)的一个视觉控件(最好是图片框)
  • 作为可滚动区域的一个视觉控件(最好是 PictureBox)
  • a HScrollBar(以及可选的 VScrollBar)来滚动可视区域
  • one visual control (preferably a PictureBox) which act as container (the viewport)
  • one visual control (preferably a PictureBox) which act as scrollable area
  • a HScrollBar (and, optionally, a VScrollBar) to scroll the view-able area

现在,在第二个 PictureBox(可滚动区域)内,您可以放置​​您在问题中提到的控件、LinesPictureBoxes.

Now, inside the second PictureBox (the scrollable area) you can place your controls, the Lines and PictureBoxes you mentioned in your question.

为什么 PictureBox 更可取?因为您可以从 ScaleMode 属性中获利,请将其设置为 3-Pixel 并使用像素精确滚动.使用 Frames 你不能这样做,你只能使用 Twips.

Why is a PictureBox preferable? Because you can profit from the ScaleMode property, set it to 3-Pixeland use pixel-exact scrolling. With Frames you can't do that, you are limited to just Twips.

使用包含的控件有两个优点:

  • 您可以在 IDE 中直观地放置和重新定位 ypu 需要的控件
  • 您只需要滚动一个控件 - 所有其他托管控件都将一起行动

你必须编写的无聊的事情是容器与滚动条的同步.

The boring thing you must code is the synchronization of the container with the ScrollBars.

但幸运的是,由于 VB6 已经走了很长一段路,您会找到足够多的此类任务的剪切和粘贴代码示例,其中一个在 VBForums 上:图片框中的滚动条

But luckily, as VB6 has been going a long way, you will find enough cut-and-paste code examples of such a task, one of which is on VBForums: Scroll bar in picturebox

一些最后的笔记:

PictureBoxes 在 VB6 中的最大尺寸限制为 16,383 x 16,383 像素.如果你的滚动区域应该更大,你可以实现一种自定义的无限滚动",并通过分组来管理你的控件的位置,你需要一些额外的编码.

PictureBoxes in VB6 are constrained to a maximum size of 16,383 x 16,383 pixels. If your scrollable area should be bigger, you may implement a kind of custom "infinite scroller", and manage the position of your controls by grouping them, and you will need some additional coding.

ScrollBars 在 VB6 中的范围可以从最小值 -32,768 到最大值 32,767.如果您需要更多,您将完成一些其他额外的编码任务.

ScrollBars in VB6 can range from a minimum value of -32,768 to a maximum value of 32,767. If you need more, you will end up with some other additional coding tasks.

如果您坚持使用 Twips,您可以获得更大的可用逻辑区域 - 例如:直到 245,745,典型的 15 TwipsPerPixel - 但您不能对 ScrollBar 使用如此大的值.

If you stick to Twips, you can have a bigger logical area available - for example: until 245,745 with the typical 15 TwipsPerPixel - but you can't use such a big value with ScrollBars.

这篇关于如何使表单的某个部分可滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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