Click to See Complete Forum and Search --> : How to reference main form ??? simple


BrianB
October 26th, 2004, 07:45 AM
I have a simple question. Say I have a c++ .net managed project. I have my main form class Form1 , and I create another class called test1. How do I reference the main form from it? I want to be able to call functions that reside in the main form. A simple code example would be VERY aqppreciated.

Thanks

lloydy
October 27th, 2004, 12:12 AM
I'm not sure why you couldn't get access to it another way (as all comes from the main form), but if you need to do it, I've attached a sample to show you how.

Let me know how you go


Also, be careful when accessing forms from other threads. All activites on a form must be on the thread that the form was created on. You may need to marshal.

Hooroo

BrianB
October 27th, 2004, 08:05 AM
Thanks!

However I want to be able to access the functions on Form1 :/ Any example of that by chance?

thanks

Idmir
October 27th, 2004, 11:05 AM
are you needing data from the main form or just the functions?

lloydy
October 27th, 2004, 06:38 PM
BrianB,

The function "UpdateLabel" is a function in Form1. You can access any function in Form1 in the same way. I'm not sure I understand what it is you want to do.

Vodzurk
October 28th, 2004, 04:42 AM
Quick guess... am in a bit of a rush...

within form2, summat like...

frmForm1 * my_Form1;
my_Form1 = dynamic_cast<frmForm1 *>(this->parent);

BrianB
October 29th, 2004, 09:58 AM
Please disregard last post .

Lloydy : I want to be able to return data form the function,. So from the class i can call a function in the main form, and get the return value or pass arguments by reference to get that data.

also, how can i do this same thing form an unmanaged class to form1?

how would i pass multiple args?

thank you much

saurabh_helloaish
November 3rd, 2004, 03:11 AM
BrainB,

u need to just declare a public variable in the nested class(or the class you r referring). This variable should be of type Form1, something like this

Form1* objForm1

Now in Form1.h load event or constructor write following line
ClassName* objClass;
objClass->objForm1 = this;

By doing this you can access all the variables of form1 and can call any function of
form1.h

thanks
saurabh