I have 2 Forms (Form1 and Form2) and a class (Class1). Form1 contains a button (Button1) and Form2 contains a RichTextBox (textBox1) When I press Button1 on Form1, I want the method (DoSomethingWithText) to be called. I keep getting "NullReferenceException - Object reference not set to an instance of an object". Here is a code example:
Form1:
namespace Test1
{
public partial class Form1 : Form
{
Form2 frm2;
Class1 cl;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
frm2 = new Form2();
cl.DoSomethingWithText();
frm2.Show()
}
}
}
Class1:
namespace Test1
{
class Class1
{
Test1.Form2 f2;
public void DoSomethingWithText()
{
f2.richTextBox1.Text = "Blah blah blah";
}
}
}
How can I call this method from within a class? Any help is greatly appreciated.