How to Automatically Resize Forms

The ElasticForm subroutine, part of CodeBank’s standard procedurelibrary, automatically repositions and sizes all controls on anSDI form when the user or code resizes the form. To use the routine,simply lay out the form as you normally would in design mode.Then call the subroutine once in the Form_Load event, with theInit parameter set to true, so that it can record the initialpositions of the controls. Call the sub in the Form_Resize event,with Init set to False, to automatically resize and repositionthe controls. The procedure accommodates any number of nestedcontainers, any ScaleMode, and all types of controls. Note, however,that the procedure relies on the Tag property to store positioninformation for each control, and so cannot be used if Tag isbeing used for another purpose (see ElasticFormArray). Also, MDIchild forms are resized by VB before the Form_Load or Form_Initializeevents, so the proportions of each form will be distorted. WithMDI children, you must use ElasticFormArray (available in CodeBank’sstandard library) and specify the optional DesignWidth and DesignHeightparameters:

 Public Sub ElasticForm(frm As Form, _        Init As Integer)On Error Resume NextDim ctl As ObjectIf Init = True Then        For Each ctl In frm.Controls                ctl.Tag = Format$(ctl.Left _                        / frm.ScaleWidth, ".0000") _                        & Format$(ctl.Top / frm.Scale_                        Height, ".0000") & Format$_                        (ctl.Width / frm.ScaleWidth, _                        ".0000") & Format$(ctl._                        Height / frm.ScaleHeight, _                        ".0000")        Next ctlElse        For Each ctl In frm.Controls                ctl.Move Val(Mid$(ctl.Tag, 1, _                        5)) * frm.ScaleWidth, _                        Val(Mid$(ctl.Tag, 6, 5)) * _                        frm.ScaleHeight, Val(Mid$_                        (ctl.Tag, 11, 5)) * frm._                        ScaleWidth, Val(Mid$(ctl.Tag, 16, _                        5)) * frm.ScaleHeight        Next ctlEnd IfEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet

payment via phone

7 Ways Technology Has Changed Traditional Payments

In today’s digital world, technology has changed how we make payments. From contactless cards to mobile wallets, it’s now easier to pay for goods and services without carrying cash or using a checkbook. This article will look at seven of the most significant ways technology has transformed traditional payment methods.