VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Size a form exactly

by Cory Ului (5 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Sizes a form to an exact size. Ever tried to size a form to say. 320 by 240 like this
Me.Width = 320 * Screen.TwipsPerPixelX
Me.Height = 240 * Screen.TwipsPerPixelY
But you want the border and title bar at the same time. And it doesn't look right at all.
Heres your answer!
(I dunno if anyone has done this before if they have. cool.) I made this years ago, but didn't know of vbcoders then.

Assumes
'Either use 'I.E. 'Call Size(Me, 320, 240) 'or 'Size Me, 320, 240 'Same result. 'Size [Form], [Width], [Height]

Rate Size a form exactly

Sub Size(sForm As Form, sWidth As Integer, sHeight As Integer)
Dim t_ScaleMode As Integer, t_Width As Integer, t_Height As Integer
 t_ScaleMode = sForm.ScaleMode
 sForm.ScaleMode = 1
 t_Width = sForm.Width - sForm.ScaleWidth
 t_Height = sForm.Height - sForm.ScaleHeight
 sForm.Width = (sWidth * Screen.TwipsPerPixelX) + t_Width
 sForm.Height = (sHeight * Screen.TwipsPerPixelY) + t_Height
 sForm.ScaleMode = t_ScaleMode
End Sub

Download this snippet    Add to My Saved Code

Size a form exactly Comments

No comments have been posted about Size a form exactly. Why not be the first to post a comment about Size a form exactly.

Post your comment

Subject:
Message:
0/1000 characters