I'm pretty new to C# - but it all went quite well - to this point.
I start with a form and a class which does most of the work (non static and in the program part). I instantiate an object of the class in form 1 and do a log in.
Then I switch over to the next form, form2. Actually, the the class does that. I have a method there, that contains the line:
this.f2 = new Form2();
and then:
f2.Show();
f2 is a class member of the type Form2 - and all just works fine - up to this point.
This Form2 just consists of a big text box in which I want to display network events. The event handler works just fine - but the reference to the form just doesn't seem to work. If I do
f2.tetBox1.Text = "Some text";
it just won't change the the text in the text box.
What am I doing wrong here?
Here is a more detailed description of what I'm doing:
Form1
passes some log in information to myProg
, being an instance of MyClass
. If the login was successful, Form1 calls myProg.makeForm();
This is what the method in MyClass looks like:
public void makeForm() {
this.f2 = new Form2();
f2.Show();
this.sendString("start f2");
}
This is MyClass.sendString()
:
private void sendString(string text) {
SystemSounds.Beep.Play();
this.f2.setTextBox(text);
}
This calls, as you see, setTextBox()
of Form2
- which I implemented as proposed here. The strange thing is, that up to this point all works well. The Form2 gets shown an textBox1 contains "start f2" - as expected. But when an event comes in, the text in textBox1 doesn't change. the beep get played all right - so the method sendString() gets called alright.
One thing I have observed: If the beep line is placed after the call to this.f2.setTextBox(text);
, it doesn't get played if the method is called from the event handler.
f2
, btw., is a private member of MyClass
:
private Form2 f2;