I have a form, called Form1 and a class, called Class1. On the form i have a textbox (textBox1) and a button (button1).
I want nothing else, just to set textBox1.Text as a string in Class1. I made a property in Form1.cs called TextValue but if i want to use it in Class1 as "string tv=Form1.TextValue;" an error occurs, that "An object reference is required for the non-static field, method, or property 'Form1.TextValue'". I think everything has set as non-static, but i am confused now.
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public string TextValue
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
namespace WindowsFormsApp2
{
public class Class1
{
string tv=Form1.TextValue;
}
}
Can you kindly help me how i should modify my code to be able to get the string "tv" with the textBox1.Text?
Thank you in advance.