hello, i'm making a program in which i need to place the controls relative to the size of the form..so could anyone tell me how to get a form's height and width form a code???

Recommended Answers

All 4 Replies

Use the reserved word "Me" to refer to the form; then use the ScaleWidth and ScaleHeight properties. Since those numbers are dependent on the ScaleMode, you will have to make sure you translate (e.g. from twips to pixels) if necessary to get the proportions right.

Then, in the Form_Resize event procedure, do some arithmetic to proportionately set the top and left properties of the controls that move, and the width and height properties of the controls that have to stretch/shrink.

thank you for your reply..it helped me to get the width and height but i would like to ask one for question..which scalemode is better twips or pixel??

Twips are finer granularity. You can look in the help file to get a more detailed explanation.

Personally, I prefer to use twips as they are device-independent. They also make for better looking graphics (if your app uses graphics objects). You don't have to worry about the resolution of the user's monitor so much. But, the numbers you manipulate are larger and you have to do some additional arithmetic to translate some of the measurements, so for some people it's a little disconcerting.

Good luck!

thank you for your reply..i googled about twips and pixels and found out that
15 twips=1 pixel
so can I write the following code to calculate the screen position of controls in pixels because I also came across the use of WinAPI functions like GetDC() and GetDeviceCaps() which has confused me a little bit

Dim WidthInPixels,HeightInPixels as integer
WidthInPixels = Me.ScaleWidth * 15
HeightInPixels = Me.ScaleHeight * 15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.