valkyr
September 13th, 2009, 02:20 PM
I've spent a ridiculous amount of time trying to find an answer to what seems like it should be so easy with no success...
How do I reference Form1 in the below, without using "((Form1)Form1.ActiveForm)"?
That works, but obviously crashes the app if you click off it while something that's using it is working.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
changetext cg1 = new changetext();
cg1.textbox1();
}
public void change_textbox_text(string input)
{
this.textBox1.Text = (input);
}
}
class changetext
{
public void textbox1()
{
((Form1)Form1.ActiveForm).change_textbox_text("OK");
}
}
}
How do I reference Form1 in the below, without using "((Form1)Form1.ActiveForm)"?
That works, but obviously crashes the app if you click off it while something that's using it is working.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
changetext cg1 = new changetext();
cg1.textbox1();
}
public void change_textbox_text(string input)
{
this.textBox1.Text = (input);
}
}
class changetext
{
public void textbox1()
{
((Form1)Form1.ActiveForm).change_textbox_text("OK");
}
}
}