By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,377 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

Access data from another form.

P: n/a
Hi All,

There are two forms, when some click happen, it fires to set form2's
viable as enable.

The form2 is for user to input some text and then the data need to be
collected into form1's textbox.

I have created a function call as public, but I still can't use it in
form2.

Please advice. Thanks!

Best regards,
Boki.

Jul 10 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Jul 10, 5:34 pm, Boki <bokit...@ms21.hinet.netwrote:
Hi All,

There are two forms, when some click happen, it fires to set form2's
viable as enable.

The form2 is for user to input some text and then the data need to be
collected into form1's textbox.

I have created a function call as public, but I still can't use it in
form2.

Please advice. Thanks!

Best regards,
Boki.
I saw a method is to create another copy of form.

ex:
private Form2 form2 = new Form2();

but I think seems not too reasonable, isn't it ?

Boki.

Jul 10 '07 #2

P: n/a
On Jul 10, 10:34 am, Boki <bokit...@ms21.hinet.netwrote:
There are two forms, when some click happen, it fires to set form2's
viable as enable.

The form2 is for user to input some text and then the data need to be
collected into form1's textbox.

I have created a function call as public, but I still can't use it in
form2.
Why not? What happens when you try? You'll need a reference to the
appropriate instance of form2 within form1, of course.

Jon

Jul 10 '07 #3

P: n/a
On Jul 10, 5:40 pm, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Jul 10, 10:34 am, Boki <bokit...@ms21.hinet.netwrote:
There are two forms, when some click happen, it fires to set form2's
viable as enable.
The form2 is for user to input some text and then the data need to be
collected into form1's textbox.
I have created a function call as public, but I still can't use it in
form2.

Why not? What happens when you try? You'll need a reference to the
appropriate instance of form2 within form1, of course.

Jon
Thanks, but I am not very understand here.

If we create another form, and then access to this form, why the
modified result also change the original form.... why not only the
copied form..
Boki.

Jul 10 '07 #4

P: n/a
It's not entirely obvious from your post, but I assume you want the text
from Form2 to become visible in Form1 without the user carrying out any
specific action, such as clicking a button that says "Fill Form1", or
something.

In that case, what you want, I guess, is to be able somewhere in code in
Form2 to be able to do something like:

Form1.FillTextBox(SomeString);

This means that you need a reference to Form1 in Form2. The easiest way of
doing this is to provide Form2 with a constructor that passes in a reference
to Form1. In Form1, you provide the FillTextBox() method.

So, in Form1 you can do:

Form Form2 = new Form(this);
Form2.Visible = true;
Form2.Show();

(or whatever)

In the Form2 constructor, you can store the reference to Form1 in an
instance variable:

Form Form1Ref;
....

public Form2(Form formoneref)
{
...
Form1Ref = formoneref;
...
}

Then in Form2 somewhere you can do:

Form1Ref.FillTextBox(MyForm2TextBox.Text);

The code above is off the top of my head, and I don't usually do
Windows.Forms stuff, so the exact syntax might be a bit wayward: but you
should get the idea.

HTH
Peter

"Boki" <bo******@ms21.hinet.netwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
Hi All,

There are two forms, when some click happen, it fires to set form2's
viable as enable.

The form2 is for user to input some text and then the data need to be
collected into form1's textbox.

I have created a function call as public, but I still can't use it in
form2.

Please advice. Thanks!

Best regards,
Boki.

Jul 10 '07 #5

P: n/a
On Jul 10, 10:52 am, Boki <bokit...@ms21.hinet.netwrote:

<snip>
Thanks, but I am not very understand here.

If we create another form, and then access to this form, why the
modified result also change the original form.... why not only the
copied form..
Have you perhaps got some static variables instead of instance
variables?

UI type work the same as "normal" types for the most part (except for
threading). Work out how you'd pass the information around in a non-UI
setting, then apply the same approach.

Jon

Jul 10 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.