> Hi, Im using two forms in the same application. Main form opens, click
> menu for secend form. This is a log on form, used to get three bits of
[quoted text clipped - 3 lines]
> etc, all works ok.
> regards robert
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
Peter Bromberg [C# MVP] - 11 Jul 2007 19:54 GMT
Rob,
Here is a short article that illustrates how to do inter-form communication
with events/delegates:
http://www.eggheadcafe.com/articles/20040229.asp
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com
> 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
zacks@construction-imaging.com - 11 Jul 2007 20:06 GMT
On Jul 11, 2:19 pm, "RobcPet...@yahoo.co.uk" <RobcPet...@yahoo.co.uk>
wrote:
> 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
I would define them in the "standard" way to define class properties.
Declare a private variable to hold the local value. Then declare a
public (or friend) property that links to the private variable. As is:
Private _myvalue as Boolean
Public Property myvalue as Boolean
Get
Return _myvalue
End Get
Set(ByVal value as Boolean)
_myvalue = value
End Set
End Property
zacks@construction-imaging.com - 11 Jul 2007 20:09 GMT
On Jul 11, 3:06 pm, z...@construction-imaging.com wrote:
> On Jul 11, 2:19 pm, "RobcPet...@yahoo.co.uk" <RobcPet...@yahoo.co.uk>
> wrote:
[quoted text clipped - 18 lines]
> End Set
> End Property
I just realized I posted VB code in a C# group. Sorry. Do you need me
to translate?
Peter Bradley - 11 Jul 2007 20:11 GMT
Ysgrifennodd RobcPettit@yahoo.co.uk:
> 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