Using this code from an early code i did in A project i was doing
Form 1 Info
Code:Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Dim dt As New DataTable("controls") dt.Columns.Add("type", GetType(String)) dt.Columns.Add("backcolor", GetType(String)) dt.Columns.Add("locationX", GetType(Integer)) dt.Columns.Add("locationY", GetType(Integer)) dt.Columns.Add("sizeWidth", GetType(Integer)) dt.Columns.Add("sizeHeight", GetType(Integer)) dt.Columns.Add("text", GetType(String)) For Each ctrl As Label In Me.Controls.OfType(Of Label)() Dim dr As DataRow = dt.NewRow dr.ItemArray = New Object() {"Label", ctrl.BackColor.Name, ctrl.Location.X, ctrl.Location.Y, ctrl.Size.Width, ctrl.Size.Height, ctrl.Text} dt.Rows.Add(dr) Next dt.WriteXml("controls.xml") End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If IO.File.Exists("controls.xml") Then Dim ds As New DataSet ds.ReadXml("controls.xml") For Each row As DataRow In ds.Tables("controls").Rows Dim ctrl As Control If row.Item(0).ToString = "Label" Then ctrl = New Label() End If Me.Controls.Add(ctrl) ctrl.BackColor = Color.FromName(row.Item(1).ToString) ctrl.Location = New Point(CInt(row.Item(2)), CInt(row.Item(3))) ctrl.Size = New Size(CInt(row.Item(4)), CInt(row.Item(5))) ctrl.Text = row.Item(6).ToString Next End If End Sub
Form2 Info
Code:Dim ListOfLabels As New List(Of Label) Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click If (From C In ListOfLabels Where C.Name = txtName.Text).Count = 0 Then Dim LB As New Label() Dim userinput1 As Integer = CInt(InputBox("Enter The Farm X Location")) Dim userinput2 As Integer = CInt(InputBox("Enter The Farm Y Location")) Dim userinput3 As Integer = CInt(InputBox("Enter The Farm Widgth Size")) Dim userinput4 As Integer = CInt(InputBox("Enter The Farm Hidgth Size")) Dim userinput5 As String = (InputBox("Whats the Name Of Feild Or Pasture")) Form1.Controls.Add(LB) LB.Size = New Size(userinput3, userinput4) LB.Location = New Point(userinput1, userinput2) LB.AutoSize = False LB.Name = txtName.Text LB.BackColor = Color.Red LB.Text = userinput5 ListOfLabels.Add(LB) ListBox1.Items.Add(LB.Name) ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Else MsgBox(String.Concat(txtName.Text, " already exists")) End If cmdRemove.Enabled = ListBox1.Items.Count > 0 End Sub Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click If ListBox1.Items.Count > 0 Then If ListBox1.SelectedIndex <> -1 Then Dim Item = CType(Form1.Controls.Find(ListBox1.Text, True)(0), Label) Form1.Controls.Remove(Item) ListOfLabels.Remove(Item) ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) If ListBox1.Items.Count > 0 Then ListBox1.SelectedIndex = 0 End If End If End If cmdRemove.Enabled = ListBox1.Items.Count > 0 End Sub
What it dose is get the listbox infromation (From Form 2 and puts it in form1. The problem im having is now during run time it places the info from form1 the info is still there when closing the the project So i need thee listbox info to stay in the listbox after closing the project and to try and remove the label which it does but if i keep it there when i close the project it stays and i cant remove it..
Something Like this
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Add(txtName.Text) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Remove(txtName.Text) End Sub




Reply With Quote