Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
I am using visual studio 2012. I am working on windows form application. In my application there are two form. At first I access form2 from form1 by clicking a button. Now I want to access form1 from form2 by clicking a button. But I can't do this. I know this is a silly problem for developer but this is painful for me. Please help me to solve this problem. Thanks in advance..........
Posted 21-Jan-13 19:25pm
Comments
Sergey Alexandrovich Kryukov at 22-Jan-13 1:30am
   
Form? Maybe this is C++/CLI and .NET?
—SA
sultan-2 at 22-Jan-13 1:38am
   
yes, you are right.
Sergey Alexandrovich Kryukov at 22-Jan-13 1:50am
   
OK. Please add the tag "Forms" and change C++ to C++/CLI (you are the one who is interested in it the most).
—SA
Sergey Alexandrovich Kryukov at 22-Jan-13 1:31am
   
By the way, if you can access one from from another (no matter how, at this moment), why not the other way around? There is no difference, really...
—SA
Rate this: bad
good
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:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].
 
—SA
  Permalink  
Comments
Abhinav S at 22-Jan-13 2:16am
   
5. I've provided another link incase OP is looking to pass data between forms.
Sergey Alexandrovich Kryukov at 22-Jan-13 2:20am
   
Thank you, Abhinav.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

if you are looking at passing data, Passing Data between Windows Forms[^] should help you out.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 22-Jan-13 2:21am
   
I never though it's a best way, but the benefit is... having the detailed article :-) I voted 4 this time.
—SA
Abhinav S at 22-Jan-13 2:23am
   
Oh well - thanks SA.

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

  Print Answers RSS
0 OriginalGriff 6,631
1 Sergey Alexandrovich Kryukov 6,345
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
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