I create a form with one button on it which shows another form with 3 textboxes. I send an instance of class Person to form2, which is supposed to fill the textboxes with the properties of Aperson. If I do not initialize the properties, the code in the loadboxes() routine of form2 does not get executed. I think this has something to do with the textbox.Enter routine, but I'm not sure why. If I remove the comment character in front of the lines initializine Aperson, then textbox3 contains "XXX" otherwise it is blank. I do not understand this behavior.
Code:Public Class Person Public Property Name() As String Public Property Age() As Integer End Class Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Aform2 As New Form2 Dim Aperson As Person = New Person 'Aperson.Name = "Anonymous" 'Aperson.Age = 29 Aform2.Aperson = Aperson Dim result = Aform2.ShowDialog End Sub End Class Public Class Form2 Public Aperson As Person Private SaveData As String Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load LoadBoxes() End Sub Private Sub LoadBoxes() TextBox1.Text = Aperson.Name.ToString TextBox2.Text = Aperson.Age.ToString TextBox3.Text = "XXX" End Sub Private Sub TextBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.Enter, TextBox2.Enter, TextBox1.Enter Dim Abox As TextBox = CType(sender, TextBox) SaveData = Abox.Text End Sub End Class




Reply With Quote