README.md
December 4, 2022 ยท View on GitHub
Description
Here is a real simple way to convert the size of vb(twips) into pixels.
More Info
| Submitted On | |
| By | SPY-3 |
| Level | Beginner |
| User Rating | 3.3 (13 globes from 4 users) |
| Compatibility | VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages) , VBA MS Access, VBA MS Excel |
| Category | Coding Standards |
| World | Visual Basic |
| Archive File |
Source Code
I found that if you want to convert the vb size(twips) into pixels simply do this
(of course change vbsize to how large the control is ex 495)
Pixels = vbsize / Screen.TwipsPerPixelX or Y
To turn pixels into vb
(Change pixels into how many pixels ex 33)
VB = pixels * Screen.TwipsPerPixelX or Y
Examples:
txtPixelHeight.Text = 495 / Screen.TwipsPerPixelX or Y
Me.Height = 33 * Screen.TwipsPerPixelX or Y
Also here is a simple function to turn twips to pixels,
Public Function TwipsToPixel(Twips As Integer, XorY As Boolean) As Integer
If XorY = True Then
TwipsToPixel = Twips / Screen.TwipsPerPixelX
Else
TwipsToPixel = Twips / Screen.TwipsPerPixelY
End If
End Function
Here is a function to turn Pixels To Twips,
Public Function PixelToTwips(Pixels As Integer, XorY As Boolean) As Integer
If XorY = True Then
PixelToTwips = Pixels * Screen.TwipsPerPixelX
Else
PixelToTwips = Pixels * Screen.TwipsPerPixelY
End If
End Function
Hope this helps and please vote.
You are free to change or modify this code however you want.