VB6:如何切换到像素而不是缇

发布于 2024-11-05 06:32:15 字数 98 浏览 0 评论 0原文

我正在重构一个 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 技术交流群。

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

发布评论

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

评论(5

黑寡妇 2024-11-12 06:32:15

我当时广泛使用了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.

段念尘 2024-11-12 06:32:15
dim iInPixels as integer
dim iInTwips as integer

iInPixels = 200
iInTwips  = iInPixels * Screen.TwipsPerPixelX
iInPixels = iInTwips / Screen.TwipsPerPixelX

正如 @drventure 所说,您将全程逆流而行,但只要您可以将逻辑隔离到一个点,情况实际上并没有那么糟糕。

dim iInPixels as integer
dim iInTwips as integer

iInPixels = 200
iInTwips  = iInPixels * Screen.TwipsPerPixelX
iInPixels = iInTwips / Screen.TwipsPerPixelX

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.

南薇 2024-11-12 06:32:15

ScaleMode 属性有帮助吗?

返回或设置一个值,该值指示使用图形方法或定位控件时对象坐标的测量单位。

Does the ScaleMode Property help?

Returns or sets a value indicating the unit of measurement for coordinates of an object when using graphics methods or when positioning controls.

↘人皮目录ツ 2024-11-12 06:32:15

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.

那小子欠揍 2024-11-12 06:32:15

我就是这样做的。
我从 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.

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