Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

Restore Layout

Restores the location and optionally the size of a form from a layout XML file.

This function works in conjunction with SaveLayout.

  • Retrieves the layout information from a shared XML file via LoadFormLayoutXml.
  • The layout is stored under a structure containing application name and form name.
  • If the application or form node is not found, the form’s position is set via SetFormDefaultLocation.
  • If the location or size elements are missing or invalid, the fallback is applied.
  • When restoreSize is True, the size is also restored along with the position.
VB
    Public Sub RestoreLayout(f As Form, 
                             Optional restoreSize As Boolean = True)

        Dim appName = GetAppNameSafe()
        Dim formName = GetEffectiveFormName(f, appName)

        Dim doc = LoadFormLayoutXml()
        Dim root = doc.Root
        If root Is Nothing Then
            SetFormDefaultLocation(f)
            Exit Sub
        End If

        Dim appNode = root.Elements("app").FirstOrDefault(Function(a) a.Attribute("name")?.Value = appName)
        If appNode Is Nothing Then
            SetFormDefaultLocation(f)
            Exit Sub
        End If

        Dim formNode = appNode.Elements("form").FirstOrDefault(Function(el) el.Attribute("name")?.Value = formName)
        If formNode Is Nothing Then
            SetFormDefaultLocation(f)
            Exit Sub
        End If

        Try
            Dim x = Integer.Parse(formNode.Element("x")?.Value)
            Dim y = Integer.Parse(formNode.Element("y")?.Value)
            f.Location = New Point(x, y)

            If restoreSize Then
                Dim w = Integer.Parse(formNode.Element("width")?.Value)
                Dim h = Integer.Parse(formNode.Element("height")?.Value)
                f.Size = New Size(w, h)
            End If
        Catch ex As Exception
            ' Valori XML corrotti → fallback
            SetFormDefaultLocation(f)
        End Try
    End Sub
Posted by ipercube


© 2026 Ipercube Design