Ysgrifennodd (e-mail address removed):
Thanks for your reply. After re reading my post, your right I have
contradicted myself. All I need to do is pass data from forw 2 to form
1. Do I declare the values in the normal way, ie public int xxxx; etc.
Regards Robert
One way of doing it would be to create a constructor for form2 that
takes an instance of a Form (or your subclass - let's say MyForm1) as a
parameter. Let's say that your second form is an instance of the
MyForm2 class.
In Form1, you create a new instance of Form2 like this:
MyForm2 myForm2 = new MyForm2(this);
You can then go on and make the new form visible and show it.
In the MyForm2 constructor, you squirrel away the reference to the first
form:
....
private MyForm1 myForm1;
....
public MyForm2(MyForm1 FirstForm)
{
myForm1 = FirstForm;
}
Let's assume that you're passing a uid and pwd back to MyForm1. To do
this, we'll assume you have two instance variables in your MyForm1
definition:
string uid;
string pwd;
Let's also assume you have a public method in your MyForm1 class called
SetUidAndPwd(string, string). Given that, and given that you've saved a
reference to your first form in your second one, you can, somewhere in
the code within your second form, do something like:
myForm1.SetUidAndPwd(uid, pwd);
Should do it. There are bound to be other ways of doing this as well.
I'm not claiming this is the best way, by any means. Perhaps a simpler
way would be to provide a method in your MyForm2 instance to return the
uid and pwd, but you would have to Hide() your form and not Close() it,
in order to call it. Of course you could close it after you've made the
call.
HTH
Peter