this is the topic connection for get user input in form 2 and display data in form 1.
This is my code in form2.
public string UserText
{
get
{
return this.textBox1.Text;
}
set
{
this.UserText = value;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Please enter keyword to search");
}
else
{
//anta data input to form1.
UserText = textBox1.Text;
}
and this is my code in form1
private void Form1_Load(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.ShowDialog();
string text = form2.UserText;
}
i want when we click on button search, it will automatically display the data when we load the form1.
when i run, it says at the setter:
make sure you do not have an infinite loop or infinite recursion.
why it says that?what did i do wrong?
i also had tried did.
public string UserText
{
get
{
return this.UserText;
}
set
{
this.UserText = value;
}
}
but it appears the same.
====EDIT==== now im trying to use this:
public string UserText
{
get
{
return this.textBox1.Text;
}
set
{
this.textBox1.Text = value;
}
}
also i tried this:
public string UserText { get; set;}
it does not show the error however, it also does not load the form1. the operation just stops there. is there anything i have done it wrong?