Click here to Skip to main content
12,953,014 members (48,120 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello, I've been doing my project but when I try to write the state a checkbox on another form

First wrote this code but did note that error:


A referral from a non-static member must be relative to a specific object

So I decided to search in google to expand my knowledge and I found this code but neither has worked for me :/ ..:

Form2 ^formA = gcnew Form2();

Error 1 error C2065: 'formA' : identificador no declarado

Error 2 error C2065: 'r' : identificador no declarado

I also found another code that replaces formA to frm2 but also caused by the same error. :/

Some Solution ?

Thanks in advance
Posted 16-Jan-13 16:15pm
Sergey Alexandrovich Kryukov 16-Jan-13 22:58pm
C++ tag is confusing. This is C++/CLI, for .NET.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:[^],[^].

With C++ and C++/CLI, due to lack of partial classes, my advice of using partial classes found in my past answers is inapplicable; just ignore this part.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In addition to solution 1, there are some alternatives that might be usefull in some cases.

In simple case, the second form might have 1 or 2 properties.

A static Show method (like MessageBox::Show) could be used if there are a lot of varied caller.

If the second form is complex, then an idea might be to have a class that represent the data (as in Model-View-Controler pattern) and be able to set or get the data object from the form.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Forgive, but do not understand much of what you meant in your other question.

They could give me a code to help me finish my proyect?
Philippe Mori 17-Jan-13 19:09pm
Well, if you want to go with properties, then you can look at MSDN documentation on
them: property. You would have a property in the second form and that property would change the state of the check box. As mentionned in my answer, using a simple type property might be adequate for very small number of properties (say < 3).

If this is not clear enough, then I would suggest you to first learn the basic of the C++/CLI language...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100