PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Re: Windows Forms internal access

Reply

Re: Windows Forms internal access

 
Thread Tools Rate Thread
Old 25-06-2003, 07:56 AM   #1
M. Veurman
Guest
 
Posts: n/a
Default Re: Windows Forms internal access


Why not change the constructors of the 9 child forms to:

public SomeChildForm(MainForm main_form)
{
this.main_form = main_form;
....

And when you need the change the text on the main form just use:

this.main_form.mainFormLabelText.Text = "bla bla"

M.Veurman


"Manuel" <mnel@mail.com> wrote in message
news:079301c3399d$b8b3b6a0$a001280a@phx.gbl...
Hi,

I have previously post a message regarding my c# windows
forms project containing 10 forms.

The main form launched when executing the application
consists of a tabbed pane form, with subforms being
displayed as buttons on panes are clicked.

As the child form changes the content of a database where
some text is stored, content which is bound to labels on
the main (tabbed) form, I need access to the main form
controls in order to reflect the database change the
moment I submit the new text, so that the user is not
faced with an update inconsistency.

In order to update the labels on the main form I need
access to them, so what I do in the child form is:

[Establishing a reference to the main form]
public Form1 mainForm;

[when the text is submitted and a button is clicked, I
want to update the labels on the main form, so I have two
options here]

1) mainForm.mainFormLabel.Text = //the new data
-- This throws an exception: since I have not instantiated
the reference.

2) mainForm = new Form1(); //makes sense
mainForm.mainFormLabel.Text = //my text

-- Since the first aproach will not work as there is no
object to work on, I go for the second one.
However, instantiating the object ´mainForm ´ results in
an exact copy of the main form being created, which will
become visible if visible is set to true.

Conclusion: I get two main forms, but I am only interested
in working/updating the one already in execution

However, instantiating a new form has an obvious
result...the creation of a new one, double the memory
occupied...plus the inconvenience of being able to operate
on the main application form.

A hassle as to say.

So, how can I work on the main form controls without
having a second form being created, nor receiveing an
exception because I have not instantiaded the form?

- I have labels as public members, so there is no way
access could be denied to them.


Please advice.

Thanks,

Manuel










  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off