Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Simple example Please

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AMP - 18 Mar 2008 23:19 GMT
Hello,
Can anyone point me to the code for a simple example of 2 classes and /
or forms referencing each other using Fields or Get/set properties.
I want both to be able to acces each others Properties and Functions.
I want the correct way, so I learn the correct way.
I know this is simple stuff, but there doesnt seem to be much out
there.
Thanks
Mike
Peter Duniho - 18 Mar 2008 23:34 GMT
> Hello,
> Can anyone point me to the code for a simple example of 2 classes and /
[quoted text clipped - 3 lines]
> I know this is simple stuff, but there doesnt seem to be much out
> there.

It is simple stuff, and isn't unique to Form-derived classes.  It's basic  
OOP.

That said, here's a simple example (class members unrelated to the  
specific question omitted for brevity):

    class Form1 : Form
    {
        void ShowForm2()
        {
            using (Form2 form2 = new Form2())
            {
                form2.ShowDialog();
                MessageBox.Show(form2.Data);
            }
        }
    }

    class Form2 : Form
    {
        public String Data
        {
            get { return "Form2 Data"; }
        }
    }

If the form's not modal and you need Form1 to keep the reference, then it  
will need to store that reference in a field somewhere.  If Form2 needs a  
reference to Form1, you can provide that when you create the Form2  
instance.  For example, pass the reference of Form1 to the constructor of  
Form2, or set a property on Form2 after it's been instantiated.

Pete

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.