Click here to Skip to main content
16,003,417 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reply to Dave's Solution Pin
Dave Kreskowiak10-Jun-05 1:32
mveDave Kreskowiak10-Jun-05 1:32 
GeneralRe: Reply to Dave's Solution Pin
Christian Graus13-Jun-05 12:10
protectorChristian Graus13-Jun-05 12:10 
GeneralReply to Fantas's Solution Pin
DJdC9-Jun-05 15:37
DJdC9-Jun-05 15:37 
GeneralRe: Reply to Fantas's Solution Pin
Christian Graus9-Jun-05 16:21
protectorChristian Graus9-Jun-05 16:21 
GeneralReply to Christian's Solution Pin
DJdC9-Jun-05 15:48
DJdC9-Jun-05 15:48 
GeneralRe: Reply to Christian's Solution Pin
Christian Graus9-Jun-05 15:53
protectorChristian Graus9-Jun-05 15:53 
GeneralReRe: Reply to Christian's Solution Pin
DJdC9-Jun-05 16:26
DJdC9-Jun-05 16:26 
GeneralRe: ReRe: Reply to Christian's Solution Pin
Christian Graus9-Jun-05 16:34
protectorChristian Graus9-Jun-05 16:34 
DJdC wrote:
OnInit?lifecycle?viewstate?

Is it a web app ? If so, stop now and learn what these things mean. If not, just tell me, as I've asked you so many times now. Your namespace suggests it is.

DJdC wrote:
The thing is Form2 has information that Form1, sometimes I'd need to pass values too, but first I need a way to link them I guess?

OK, so Form1 is causing Form2 to be visible ? When you put 'Form1 form = new Form1', you create ANOTHER Form1, it has nothing to do with any other instance that may be visible.

DJdC wrote:
I believe by simply calling the function to be performed as per normal, half my battle is won.

I'm not sure that this is the case, if you don't have a Form1 instance visible ( i.e. it's not a web app, and Form1 creates and shows Form2, or they are somehow both visible on screen at once ), then the battle is lost, there IS no Form1, and therefore no information.

DJdC wrote:
Dave said to see posts regarding adding a reference of Form1 to Form2 or something like that?

Yes. In Form2, make an instance of Form1 as a member variable. Then make the default constructor private, and create a constructor that takes an instance of Form1 as a parameter, and pass in 'this' from Form1 when you create Form2. Then you can access the actual instance of Form1 that is visible from within Form2.

Form2:

class Form2
{

private Form1 parentForm = null;

// So it cannot be used
private Form2(){};

public Form2(Form1 parent)
{
parentForm = parent;
}

}

in Form1:

Form2 form2 = new Form2(this);
form2.ShowDialog(); // Add checks to dialog result if needed

Now, if your code does not conform to this pattern ( where it's a windows app and Form1 creates Form2, then you need to further explain your problem.

And I'll reiterate that if Form1 and Form2 share some data, it should exist in a seperate class, as a static instance, so that both forms can access it, if both need it, then it belongs to both and not one or the other.


Christian Graus - Microsoft MVP - C++
GeneralReRe: ReRe: Reply to Christian's Solution Pin
DJdC9-Jun-05 17:06
DJdC9-Jun-05 17:06 
GeneralRe: ReRe: ReRe: Reply to Christian's Solution Pin
Christian Graus9-Jun-05 17:12
protectorChristian Graus9-Jun-05 17:12 
GeneralReRe: ReRe: ReRe: Reply to Christian's Solution Pin
DJdC9-Jun-05 17:45
DJdC9-Jun-05 17:45 
GeneralRe: ReRe: ReRe: ReRe: Reply to Christian's Solution Pin
Christian Graus9-Jun-05 17:51
protectorChristian Graus9-Jun-05 17:51 
GeneralReRe: ReRe: ReRe: ReRe: Reply to Christian's Solution Pin
DJdC9-Jun-05 19:10
DJdC9-Jun-05 19:10 
GeneralRe: ReRe: ReRe: ReRe: ReRe: Reply to Christian's Solution Pin
Christian Graus13-Jun-05 11:56
protectorChristian Graus13-Jun-05 11:56 
GeneralRe: Please Help! Function on Separate Form Pin
Jack Bond13-Jun-05 2:23
Jack Bond13-Jun-05 2:23 
GeneralGame Programming Pin
Sabry19058-Jun-05 22:55
Sabry19058-Jun-05 22:55 
GeneralRe: Game Programming Pin
Philip Price8-Jun-05 23:20
Philip Price8-Jun-05 23:20 
GeneralRe: Game Programming Pin
MoustafaS9-Jun-05 0:49
MoustafaS9-Jun-05 0:49 
GeneralRe: Game Programming Pin
Christian Graus9-Jun-05 17:52
protectorChristian Graus9-Jun-05 17:52 
GeneralRe: Game Programming Pin
JDUK12-Jun-05 11:53
JDUK12-Jun-05 11:53 
GeneralConverting Code Pin
Sabry19058-Jun-05 22:49
Sabry19058-Jun-05 22:49 
GeneralRe: Converting Code Pin
Philip Price8-Jun-05 23:17
Philip Price8-Jun-05 23:17 
GeneralRe: Converting Code Pin
Carsten Zeumer8-Jun-05 23:25
Carsten Zeumer8-Jun-05 23:25 
GeneralRe: Converting Code Pin
Dave Doknjas9-Jun-05 16:04
Dave Doknjas9-Jun-05 16:04 
GeneralKeeping data in clipboard after app closes Pin
gubber8-Jun-05 22:31
gubber8-Jun-05 22:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.