You want to call the ShowDialog(). This will stop the code execution in the main form until the GetUserInput form in closed. If you just call Show() the GetUserInput form is shown but code continues executing in the main form before anything is entered in GetUserInput form. Also, as Ron said, you need to reference your property via GetUserInput from and not like you did. And you shouldn't use public variables like you did, make a property that maps to a private variable. Try this...
In your newMenuItem_Click event do this...
private void newMenuItem_Click(object sender, EventArgs e)
{
GetUserInput f = new GetUserInput();
f.ShowDialog();
MessageBox.Show(f.UserInput);
f.Dispose();
f = null;
}
And in your GetUserInput form, do this...
public partial class GetUserInput : Form
{
public GetUserInput()
{
InitializeComponent();
}
string _userInput = string.Empty;
public string UserInput
{
get { return _userInput; }
set { _userInput = value; }
}
private void GetUserInput_Load(object sender, EventArgs e)
{
txtBoxGetUserInput.Focus();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnOK_Click(object sender, EventArgs e)
{
_userInput = txtBoxGetUserInput.Text;
this.Close();
}
}