[英]Centering elements when resizing windows in VB6
I'm building an application in VB6 where the standard form size is 1024x768, for the older monitors that will see it. 我正在标准格式为1024x768的VB6中构建一个应用程序,供较早的显示器使用。 Some of the users will, however, have higher resolutions available, and I'd like the program to still look nice when they maximize the screen. 但是,有些用户将具有更高的分辨率,我希望该程序在最大化屏幕时仍然看起来不错。 I don't want to resize the elements on the form at all, but I am looking to recenter everything. 我根本不想调整表单上元素的大小,但我希望对所有内容进行更新。 There are two options as I see it, and I don't really like either one: 我看到有两种选择,但我并不喜欢其中一种:
I don't love the first one because ugh, and I don't love the second one because it's such an ad hoc solution. 我不喜欢第一个,因为呃,我不喜欢第二个,因为这是一个特别的解决方案。 Also, while I like the idea behind the first one more, it has the problem of permanence: if I need to go back and change some elements, I'm then stuck rewriting lots of repositioning code. 同样,虽然我更喜欢第一个背后的想法,但是它存在永久性问题:如果我需要返回并更改某些元素,那么我就不得不重写许多重新定位的代码。 And the second one has a sorta similar issue, that I'd lose one of the nice things that VB6 does provide: being able to see the grid structure of the form. 第二个也有类似的问题,我将失去VB6确实提供的一件好事:能够看到表单的网格结构。
Anyone know of any magic solutions? 任何人都知道魔术解决方案吗?
I'm currently leaning towards the PictureBox, just because the prospect of writing and undoubtedly rewriting all that positioning code is depressing. 我目前倾向于使用PictureBox,因为编写和无疑重写所有定位代码的前景令人沮丧。 The issue here then is that I already have these 50+ elements on the form, but I'd need them to be in the PictureBox. 那么这里的问题是我已经在窗体上拥有了这50多个元素,但是我需要将它们放在PictureBox中。 I can copy and paste without creating the array it always seems to want to make, but then I'd have to go through an rename them all... so my second question, is there any simple way to transfer a preexisting element on a form into a PictureBox? 我可以复制和粘贴而不创建似乎总是想创建的数组,但是然后我必须对它们全部进行重命名...所以我的第二个问题是,有什么简单的方法可以将预先存在的元素转移到形式成一个PictureBox?
Thanks everyone! 感谢大家!
There is no free lunch. 天下没有免费的午餐。 If you want your VB6 application to "look nice" when resized, you have to write the dynamic sizing logic in the Form_Resize
event. 如果希望您的VB6应用程序在调整大小时“看起来不错”,则必须在Form_Resize
事件中编写动态大小调整逻辑。 Otherwise, as others have stated, you'll have large gray areas with everything crammed in the upper left corner. 否则,正如其他人所述,您将有很大的灰色区域,所有内容都塞在左上角。 Centering in a PictureBox
isn't much better. 在PictureBox
居中并没有更好。 Either way, it will look non-standard and amateurish. 无论哪种方式,它看起来都是非标准的和业余的。
I've written this type of code for several VB6 applications. 我已经为多个VB6应用程序编写了此类代码。 I'll agree that it's a little tiresome to write, but it's not difficult. 我同意写起来有点累,但这并不困难。 You just have to think about: 您只需要考虑:
"Anchor" type properties make this type of code unnecessary in VB.NET. “锚点”类型属性使VB.NET中不需要这种类型的代码。 If you think about that for a minute, you'll see that if a few properties can handle this logic, the lines of code needed to do the same can't be all that complex. 如果您仔细考虑一下,您会发现,如果有一些属性可以处理此逻辑,那么执行相同操作所需的代码行就不会那么复杂。 Once you have the first control positioned and sized, you can base other controls positions off that control's top, left, width, and height, and just walk your way across the form. 一旦第一个控件的位置和大小确定后,就可以将其他控件的位置作为该控件的顶部,左侧,宽度和高度的基础,然后在表单中移动。
When you get it right, I think you will find that it actually is worth the effort. 如果您做对了,我认为您会发现实际上值得付出努力。
If the elements are nog going to change size or position in relation to each other I would probably go for the PictureBox
approach. 如果元素要改变相对于彼此的大小或位置,我可能会选择PictureBox
方法。 I don't see how that would be bad really. 我不知道那会是多么糟糕。
If the controls need to be resized or relocated, I would (and God knows I used to) write loads of resizing code... 如果需要调整控件的大小或位置,我(上帝知道我曾经)写过很多调整代码的代码...
http://www.functionx.com/vbnet/Lesson08.htm http://www.functionx.com/vbnet/Lesson08.htm
Look at Control Containers. 查看控制容器。 As I noted in comment the second solution you described isn't ad hoc - it is organized. 正如我在评论中指出的那样,您描述的第二个解决方案不是临时性的-它是有组织的。 UI is all about containers. UI都是关于容器的。
You're right in feeling icky about PictureBox, though. 不过,您对PictureBox感到讨厌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.