Hi,
I wrote positions of my dialogs in separate location text files.
This is the “SaveLoc” method, which has two parameters:
frmDialog As Window, strFileName As String
[code]// This method saves the location of frmDialog
Dim tosValue As TextOutputStream
Dim f_Temp As FolderItem
Dim strLocList As String
// Assemble Location list
strLocList = Str(frmDialog.Left) + “#” +_
Str(frmDialog.Top) + “#” +_
Str(frmDialog.Width) + “#” +_
Str(frmDialog.Height)
f_Temp = GetFolderItem(f_Dialogs_Loc.NativePath + strFileName)
tosValue = TextOutputStream.Create(f_Temp)
tosValue.WriteLine(strLocList)
tosValue.Close[/code]
This is the “LoadLoc” loading code :
[code]// This method loads the last saved location and size
// of a form specified in frmDialog. When there is no
// location file for that form present, the present location
// and sizes are saved in a new location file.
Dim tisValue As TextInputStream
Dim tosValue As TextOutputStream
Dim f_Temp As FolderItem
Dim strPosList As String
// Does the filename for the specified form exists?
f_Temp = GetFolderItem(f_Dialogs_Loc.NativePath + strLocFileName)
If f_Temp.Exists Then
// Location file does exist
// Read dialog locations
tisValue = TextInputStream.Open(f_Temp)
strPosList = tisValue.ReadLine
tisValue.Close
Else
// Location file does NOT exist
// Assemble Position list
strPosList = Str(frmDialog.Left) + “#” +_
Str(frmDialog.Top) + “#” +_
Str(frmDialog.Width) + “#” +_
Str(frmDialog.Height)
// Save Position list
tosValue = TextOutputStream.Create(f_Temp)
tosValue.WriteLine(strPosList)
tosValue.Close
End If
// Set Dialog location
frmDialog.Left = Val(NthField(strPosList, “#”, 1))
frmDialog.Top = Val(NthField(strPosList, “#”, 2))
frmDialog.Width = Val(NthField(strPosList, “#”, 3))
frmDialog.Height = Val(NthField(strPosList, “#”, 4))
// Done[/code]
The above code has the same parameters as the SaveLoc method. f_Dialog_Loc is a global property which points to the place within my user directory where the files are stored. For each dialog there is a separate file. By deleting a file, position location values are restored to standard.
In my dialogs I have a constant “cstrLocFilename” which contains the name of the dialog location file. In my “Open” event of the dialog I put the following call :
LoadLoc(me, me.cstrFileName)
which load and set the location of the dialog.
In the Moved or resized events of the dialog I save the location.
Instead of binary files, I use text files because the user can also easily change values. Values are always stored in this order :
Left
Top
Right
Bottom
I hope this helps.
Chris