VB6:如何切换到像素而不是缇
我正在重构一个 VB6 应用程序。任何控件的测量值均以缇为单位。 VB6 中是否可以设置控件使用像素而不是缇?谢谢
I am refactoring a VB6 application. The measurements of any of the controls are in twips. Is it possible in VB6 to set a control to use pixels instead of twips? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我当时广泛使用了scalemode,我只能说不要打扰。它没有得到适当的普遍支持,这意味着无论如何您最终都会将某些东西转换回缇。
VB6 是基于缇的,不管你喜不喜欢,所以如果你尝试做基于像素的事情,你将一直与当前的情况作斗争。
幸运的是,VB.net 最终结束了这一切,并且完全基于像素,您仍然可以更改视口缩放,但 .net 似乎比 Vb6 处理得更好。
I worked extensively with scalemode back in the day and all I can say is don't bother. It wasn't properly universally supported, which meant that you'll end up converting back to twips for some things anyway.
VB6 is twips based, like it or not, so if you try to do things pixel based, you'll be fighting the current the whole way.
Fortunately VB.net finally ended all that, and is completely pixel based, you can still alter you viewport scaling but .net seems to handle that much better than Vb6.
正如 @drventure 所说,您将全程逆流而行,但只要您可以将逻辑隔离到一个点,情况实际上并没有那么糟糕。
As @drventure said, you'll be rowing against the current the whole way, but it really isn't all that bad, as long as you can isolate the logic to a single spot.
ScaleMode 属性有帮助吗?
Does the ScaleMode Property help?
Microsoft 知识库文章:如何将缇转换为像素
上面的链接适用于 Access VBA,但可以使用也可以用VB6。我不知道本机 VB6 功能可以满足您的需要。据我所知,ScaleMode 不适用于您想要做的事情(尽管事实上它似乎是为了解决您的确切问题而存在的)。
编辑:正如我所想,ScaleMode 并没有解决我当时遇到的我问题。根据您想要做什么,它可能会很好地解决您的问题。我当然会首先尝试,因为它会生成更简单、更易于维护的代码。
Microsoft Knowledge Base article: How to Convert Twips to Pixels
The link above is for Access VBA but will work with VB6 as well. I'm not aware of native VB6 functionality to do what you need. From what I remember ScaleMode will not work for what you want to do (despite the fact that it seems to exist to solve your exact problem).
EDIT: As I'm thinking about it, ScaleMode did not solve my problem that I had at the time. Depending on what you are trying to do, it may solve your problem just fine. I'd certainly try that first since it will produce simpler, more maintainable code.
我就是这样做的。
我从 Form1.Picture.Width 获得了缇,通过使用 Pixelize 进行除法,您可以在 VB6 脚本中的任何地方获得像素。
在一般声明中
Const Pixelize As Double = 26.45833333
Command3.Caption = "像素:" & Int(Form1.Picture.Width / 像素化) & “x”& Int(Form1.Picture.Height / Pixelize)
对我有用,也许你会有所帮助。
I did it this way.
I got the Twips from Form1.Picture.Width and by dividing with pixelize you get pixels ANYWHERE in VB6 Script.
In General Declarations
Const pixelize As Double = 26.45833333
Command3.Caption = "Pixels: " & Int(Form1.Picture.Width / pixelize) & "x" & Int(Form1.Picture.Height / pixelize)
Works for me, maybe you are helped.