Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 1, 1997

Save Form Position and Size Using SaveSetting

SaveSetting and GetSetting make writing application settings a breeze. These two utility functions retrieve and store the current forms position:
 
Public Sub FormPosition_Get(F As Form)
' Retrieve Form F's position from an 
' ini/reg file and position it 
' accordingly
Dim buf As String
Dim l As Integer, t As Integer
Dim h As Integer, w As Integer
Dim pos As Integer

buf = 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) \ 2
Else
        ' 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, h
End If
End Sub

Public Sub FormPosition_Put(F As Form)
' Write form F's top,left,height and 
' width properties to the reg/ini file 
' for the application
Dim buf As String
buf = F.left & "," & F.top & "," & _
        F.Width & "," & F.Height
SaveSetting app.EXEName,_
        "FormPosition", F.Tag, buf
End Sub
You should place these routines in a module and call them from the forms' Load and Unload events. You must place the name of the form in its Tag property for these utilities to work:
 
Sub Form_Load()
        FormPosition_Get Me
End Sub
Sub Form_Unload()
        FormPosition_Put Me
End Sub
Rob Parsons
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date