473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

referenceing a class in a another .cs file

I have a form1 that creates form2. I also have a class A in a third .cs
file.
I do a new in form1 that creates A.
How do I reference A (and its data) form2.

All the examples I see only use only one .cs file, and only one form.

Thanks! Larry Hilley
Nov 15 '05 #1
2 1954
Hi Larry,

You can pass the instance of class A from Form1 to Form2 either
through Form2's constructor or through a public method/property
in Form2.
Form2 can then stash away the instance of Class A in a field
that it can use to later access A's properties/methods.

For example, when Form1 creates Form2, it would do something like:

public void CreateForm()
{
A obj = new A();
Form2 myChildForm = new Form2(obj);
myChildForm.ShowDialog(this);
}

(or)

public void CreateForm()
{
A obj = new A();
Form2 myChildForm = new Form2();
myChildForm.MyData = obj;
myChildForm.ShowDialog(this);
}
Regards,
Aravind C
"Larry Hilley" <hi****@comcast.net> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
I have a form1 that creates form2. I also have a class A in a third .cs
file.
I do a new in form1 that creates A.
How do I reference A (and its data) form2.

All the examples I see only use only one .cs file, and only one form.

Thanks! Larry Hilley

Nov 15 '05 #2
Larry Hilley <hi****@comcast.net> wrote:
I have a form1 that creates form2. I also have a class A in a third .cs
file.
I do a new in form1 that creates A.
How do I reference A (and its data) form2.

All the examples I see only use only one .cs file, and only one form.


The number of .cs files is irrelevant. Forms are just classes like any
other - so do what you'd do elsewhere: make sure that class A has a
reference to the second form, possibly passing it in the constructor to
A.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Fu Bo Xia | last post by:
the java.lang.Object.forName method takes a java class name and returns a Class object associated with that class. eg. Class myClass = Object.forName("java.lang.String"); by if i only know the...
2
by: Pierre Rouleau | last post by:
Greetings, I'm wondering why the >> operator does not use the write() method of a class derived from the built-in file class as in DerivedFile below. In the following example: - StringFile...
3
by: Kevin Buchan | last post by:
I have a web page that I want to JIT compile using the 'src' attribute in the Page directive. I've done this many times and life has normally been great, as a result. However, I find myself...
16
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
7
by: Joe | last post by:
Hello All: I have a solution with four projects (UI, Business, Database and Messaging). UI has references to Business and Messaging; Business has a refernce to Database; Messaging has a...
0
by: Daniel Sélen Secches | last post by:
I found a good class to do a simple FTP. Very good.... I'm posting it with the message, i hope it helps someone ============================================================== Imports...
1
by: bafidi | last post by:
i have one solutio 3 project in i 1. Stok 2. Muhasebe 3. Connection1 (Startup project) i have a clas in it baglan 1. project i make a dl 2. project also dl 3. ex
7
by: tshad | last post by:
I have a problem with a VS 2003 project. This project was designed and works fine in VS 2003. But trying to open the project I get the following error....
2
by: adweaver | last post by:
am I able to call text from either a text file, or from an html document, to show on my webpage? I'm eventually going to have 10 versions of a webpage running. All with minor differences. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.