Imports System.Xml Public Class ProgParameter Private vcst_Path As String Private vcst_File As String Public Function SaveForm(ByVal WinForm As Form) As Boolean Dim IniDatei As XmlDocument Dim RootNode As XmlNode Dim Attr As XmlAttribute Dim FormsNode As XmlNode Dim NewFormNode As XmlNode Dim OldFormNode As XmlNode Dim WinStateNode As XmlNode Dim PosNode As XmlNode Dim SizeNode As XmlNode Dim NodeList As XmlNodeList Dim elem As XmlElement Dim FormFound As Boolean Dim FormName As String = WinForm.Name ' Dummy use for OldFormNode OldFormNode = Nothing IniDatei = New Xml.XmlDocument IniDatei.Load(vcst_Path & "\" & vcst_File) ' Get Forms Collection NodeList = IniDatei.GetElementsByTagName("Form") ' Auflistung durchsuchen For Each elem In NodeList ' Search for "Name" Attribute (Name of the Form) If elem.HasAttribute("Name") Then ' Read the value If elem.GetAttribute("Name") = FormName Then ' If found then exit loop OldFormNode = elem FormFound = True Exit For End If End If Next ' New Node for the form NewFormNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Form", "") ' append Attributes Attr = IniDatei.CreateAttribute("Name") Attr.Value = FormName NewFormNode.Attributes.Append(Attr) Attr = IniDatei.CreateAttribute("Typ") Attr.Value = "FORM" NewFormNode.Attributes.Append(Attr) Attr = IniDatei.CreateAttribute("Caption") Attr.Value = WinForm.Text NewFormNode.Attributes.Append(Attr) ' Search the Parent Node (it's "Forms") NodeList = IniDatei.GetElementsByTagName("Forms") If NodeList.Count > 0 Then ' Formsnode found FormsNode = NodeList(0) Else ' Create the Forms Node NodeList = IniDatei.GetElementsByTagName("Startparameter") RootNode = NodeList(0) FormsNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Forms", "") RootNode.AppendChild(FormsNode) End If If Not FormFound Then ' append new Formnode FormsNode.AppendChild(NewFormNode) Else ' replace the current node with the new node FormsNode.ReplaceChild(NewFormNode, OldFormNode) End If ' append the new values WinStateNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Winstate", "") Attr = IniDatei.CreateAttribute("Value") Attr.Value = WinForm.WindowState WinStateNode.Attributes.Append(Attr) PosNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Loacation", "") Attr = IniDatei.CreateAttribute("X") Attr.Value = WinForm.Location.X PosNode.Attributes.Append(Attr) Attr = IniDatei.CreateAttribute("Y") Attr.Value = WinForm.Location.Y PosNode.Attributes.Append(Attr) SizeNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Size", "") Attr = IniDatei.CreateAttribute("Width") Attr.Value = WinForm.Size.Width SizeNode.Attributes.Append(Attr) Attr = IniDatei.CreateAttribute("Height") Attr.Value = WinForm.Size.Height SizeNode.Attributes.Append(Attr) ' append the valuenodes NewFormNode.AppendChild(WinStateNode) NewFormNode.AppendChild(PosNode) NewFormNode.AppendChild(SizeNode) ' save file IniDatei.Save(vcst_Path & "\" & vcst_File) End Function Public Function ExistIniFile() As Boolean Dim vlst_File As String ' built the filename vlst_File = vcst_Path & "\" & vcst_File If System.IO.File.Exists(vlst_File) Then Return True Else Return False End If End Function Public Function CreateIniFile() As Boolean Dim IniDatei As Xml.XmlDocument Dim Definition As Xml.XmlNode Dim RootNode As Xml.XmlNode Dim FormsNode As Xml.XmlNode Dim DataNode As Xml.XmlNode Dim Attr As Xml.XmlAttribute ' Create the document IniDatei = New Xml.XmlDocument ' xml Definition Definition = IniDatei.CreateNode(Xml.XmlNodeType.XmlDeclaration, " ", "") IniDatei.AppendChild(Definition) ' Create Root Node RootNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Startparameter", "") IniDatei.AppendChild(RootNode) Attr = IniDatei.CreateAttribute("ID") Attr.Value = "ROOT" RootNode.Attributes.Append(Attr) ' Create Forms Node ' it will contain all Form Data (Location, Size ...) FormsNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Forms", "") RootNode.AppendChild(FormsNode) ' Create Data Node ' it will contain the Data for Database Connection (User, Pwd, Service) DataNode = IniDatei.CreateNode(Xml.XmlNodeType.Element, "", "Database", "") RootNode.AppendChild(DataNode) ' Save Ini File IniDatei.Save(vcst_Path & "\" & vcst_File) End Function Public Sub New() ' look with defaults (path and file) Me.New(Application.LocalUserAppDataPath, "INI.XML") End Sub Public Sub New(ByVal vlst_FileName As String) ' look at default path Me.New(Application.LocalUserAppDataPath, vlst_FileName) End Sub Public Sub New(ByVal vlst_Path As String, ByVal vlst_FileName As String) vcst_File = vlst_FileName vcst_Path = vlst_Path If Not Me.ExistIniFile Then Me.CreateIniFile() End If End Sub Public ReadOnly Property IniPath() As String Get Return vcst_Path End Get 'Set(ByVal vlst_Path As String) ' vcst_Path = vlst_Path 'End Set End Property Public ReadOnly Property IniFile() As String Get Return vcst_File End Get 'Set(ByVal vlst_file As String) ' vcst_File = vlst_file 'End Set End Property Protected Overrides Sub Finalize() MyBase.Finalize() End Sub End Class