Well you have not even shown the child form yet. So it's unlikely that the textbox has been filled in (or if it has even been created yet).
Also, instead of accessing the child control in that form directly, expose a public property that returns the text from the textbox. After you show the form, access the form's public property to get the text you want and then assign it to the
userName
field.
In the child dialog, expose the text as follows:
public string Username
{
get
{
return textBoxUsername.Text;
}
}
Now in the parent dialog do this:
string userName;
var dialog = new ChildForm();
if (dialog.ShowDialog() == DialogResult.OK)
{
userName = dialog.Username;
}