Save Form Position and Size Using SaveSetting

SaveSetting and GetSetting make writing application settings a breeze. These two utility functions retrieve andstore the current forms position:

 Public Sub FormPosition_Get(F As Form)' Retrieve Form F's position from an ' ini/reg file and position it ' accordinglyDim buf As StringDim l As Integer, t As IntegerDim h As Integer, w As IntegerDim pos As Integerbuf = GetSetting(app.EXEName, _        "FormPosition", F.Tag, "")If buf = "" Then         ' defaults to centering the form        F.Move (Screen.Width - F.Width)  _                2, (Screen.Height - F.Height)  2Else        ' extract l,t,w,h and move the form        pos = InStr(buf, ",")        l = CInt(Left(buf, pos - 1))        buf = Mid(buf, pos + 1)        pos = InStr(buf, ",")        t = CInt(Left(buf, pos - 1))        buf = Mid(buf, pos + 1)        pos = InStr(buf, ",")        w = CInt(Left(buf, pos - 1))        h = CInt(Mid(buf, pos + 1))        F.Move l, t, w, hEnd IfEnd SubPublic Sub FormPosition_Put(F As Form)' Write form F's top,left,height and ' width properties to the reg/ini file ' for the applicationDim buf As Stringbuf = F.left & "," & F.top & "," & _        F.Width & "," & F.HeightSaveSetting app.EXEName,_        "FormPosition", F.Tag, bufEnd Sub

You should place these routines in a module and call them from the forms’ Load and Unload events. You mustplace the name of the form in its Tag property for these utilities to work:

 Sub Form_Load()        FormPosition_Get MeEnd SubSub Form_Unload()        FormPosition_Put MeEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS