title: Passing data between forms DIRECTLY
body: <p>I'm making a "Preference form" that will hold all the users preferences and when they go to Apply/Save I want the new values to transfer back to the main form and updateand close the form2. In the past I have done this like this:</p>
  
  <pre><code>Private Sub PreferencesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PreferencesToolStripMenuItem.Click
      Preferences.Show()
  End Sub
  </code></pre>
  
  <p>and when I click the "Apply/Save" button before it closes I would Transfer all data like this:</p>
  
  <pre><code>form1.textbox.text = form2.textbox.text
  </code></pre>
  
  <p>Is there anything wrong doing it this way??</p>
  
  <p>What I have been reading is I should be doing it like this:</p>
  
  <pre><code>Private Sub PreferencesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PreferencesToolStripMenuItem.Click
      Dim dialog As New Preferences
      dialog.ShowDialog()
  End Sub
  </code></pre>
  
  <p>And when when they click "Apply/Save" it would take all the values from Form2 and store them in a private variable (or Property) in Form2 and when that form closes I would then access the value like this:</p>
  
  <pre><code>Private Sub PreferencesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PreferencesToolStripMenuItem.Click
      Dim dialog As New Preferences
      dialog.ShowDialog()
  
      form1.textbox.text = dialog.variable
  End Sub
  </code></pre>
  
  <p>Why would this be a better way of doing this? </p>
  
  <p>UPDATE....Looking at the code below this is just a SMALL sample of all the options I will have. What is the best way to collect of the data into the object to use when serializing?</p>
  
  <pre><code>    &lt;Serializable&gt;
  Public Class Preference
  
  #Region "Properties"
      Public Property ScaleLowest As String = "5"
      Public Property ScaleHighest As String = "200"
      Public Property ScaleInc As String = "5"
      Public Property ThickLowest As Double = 0.125
      Public Property ThickHighest As Double = 4
      Public Property ThickInc As Double = 0.125
      Public Property WidthLowest As Double = 0.125
      Public Property WidthHighest As Double = 0.6
      Public Property WidthInc As Double = 0.125
      Public Property LengthLowest As Double = 1
      Public Property LengthHighest As Double = 96
      Public Property LengthInc As Double = 1
      Public Property FractionON As Boolean = False
      Public Property DecimalON As Boolean = True
      Public Property ColorSelection As String = "Colors"
      Public Property FinalColor As String = "255, 255, 0"
      Public Property roughColor As String = "255, 255, 100"
      Public Property SplashON As Boolean = False
      Public Property LogInON As Boolean = False
  #End Region
  
      Public Sub New()
          'for creating new instance for deserializing
      End Sub
  
      Public Sub GatherAllData()
  
          'Save Defaults
          SaveSerializeObj()
  
      End Sub
  
      Public Sub SaveSerializeObj()
          'Get Changes?????
  
          'Serialize object to a text file.
          Dim objStreamWriter As New StreamWriter("C:\Users\Zach454\Desktop\test.xml")
          Dim x As New XmlSerializer(Me.GetType)
          x.Serialize(objStreamWriter, Me)
          objStreamWriter.Close()
  
      End Sub
  
      Public Function LoadSerializeObj() As Preference
  
          'Check if new file need created
          If File.Exists("C:\Users\454\Desktop\test.xml") = False Then
              SaveSerializeObj()
          End If
  
          'Deserialize text file to a new object.
          Dim objStreamReader As New StreamReader("C:\Users\454\Desktop\test.xml")
          Dim newObj As New Preference
          Dim x As New XmlSerializer(newObj.GetType)
          newObj = CType(x.Deserialize(objStreamReader), Preference)
          objStreamReader.Close()
  
          Return newObj
      End Function
  </code></pre>