sharing variables/information between two forms

Posted on 2006-03-20
Last Modified: 2010-04-24
Visual c++ .net express 2005
windows xp

I have two forms, inside the same application. Form1 creates Form2, so I assume it is a "child" of some sort. Anyway, I am collecting data via rs232 in the main form (form1) and would like to pass that information to form2. I was looking for some function like "GetParent" to get a handle to the original or any other way that is typical to pass information between forms. I have tried to even compile an old c++ singleton class that I have to share the information, but it doesn't mix well with managed c++ (because of the static variables?) . Anyway, is there a "proper" way to handle this ? I don't really want an MDI type solution. I would like this to all be independent forms so that non pertinent forms can just be minimized or hidden when they aren't needed, as well as the ability to see both forms. Sample code would be most helpful! I'm pretty wet behind the ears on this, as I usually just do embedded C and VHDL.

Question by:fenriss_wolff
    LVL 8

    Accepted Solution

    Since your form2 is created by form1, then form1 can store a pointer to form2 and call functions or set member variables for form2 directly. Whether form2 is a real "child" of form1 or not is something you define when you create form2. You could also send data to form2 as messages.

    Author Comment

    I'm so new that I didn't even know you forms were inherited, and all I needed to do was create a set function with a pointer to my data that I want to pass from Form1 . Thx!

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Safearray problem c++ 4 73
    VC++ 6.0 issue 3 63
    using dll from another object 1 73
    C language IDE – Compilers installation 14 47
    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now