Dialog access to callers controls

  • Thread starter Thread starter Lucas Graf
  • Start date Start date
L

Lucas Graf

I feel like a bonehead because this seems so easy.

I have 2 forms in the same namespace, Form1 and Form2.

Form1 is a MDI Container.
Form1 has a status bar : statusbar1
Form1 has a basic menu : File -> Show Dialog

Form2 is a form with a checkbox on it.

Form2 is shown via ...
WindowsApplication1.Form2 dialogForm2 = new Form2();

dialogForm2.ShowDialog();


All i want to do (for this examples sake) is when I click on the checkbox on
Form2 is update the statusbar1.Text on Form1.

This is easy enough when you don't want to show it as a dialog, and you just
set the Parent property of Form2 to Form1, but for whatever reason I can't
figure out how to do it when I want to show it as a dialog.
 
You might consider exposing an event on Form2 that Form1 can hook and
receive notification of the checkbox change. Specifically, you would create
an event on Form2, then before Form1 calls the ShowDialog method of Form2
you hook into the created event, then you may send any information you want
through EventArgs to Form1, allowing Form1 to handle how the information is
displayed within itself. This way if you were to decide that the information
from Form2 needs to be shown to the user in a different place on Form1, you
don't need to make changes to code for the Form2 class. Thus, IMO, it
becomes more logical to maintain long term.
 
How about in this situation, which is the situation I really need to use it
in.

I have a treeview on Form1, I create a new node in Form2 and need to add it
to the treeview on Form1. Would I do the same thing?
 
Yep. Just create a custom EventArgs that contains the node to add, and then
in the event handler pull out the node and shove it in the treeview.
 
Cool.
Thx Tim!


Tim Wilson said:
Yep. Just create a custom EventArgs that contains the node to add, and
then
in the event handler pull out the node and shove it in the treeview.
 
Back
Top