Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing main form from functions in other classes

Status
Not open for further replies.

pjmartins

Programmer
Nov 5, 2004
4
US
I'm trying to draw a line on a form through a function which is in a class that I created inside another .h and .cpp file. But I cannot give it access to the main form or it's controls. Is there any way that I can pass the form into the functions of the class or a way that I can access the main form or maybe just a picturebox on the form in which I can draw too. And if so, how can I declare a temporary form / picturebox inside the class which I can then assign to the form / picturebox of the main form to?

PJ
 
Just give your other form a member variable that is a pointer to the main form.
 
What would I declare that pointer as, I've tried to use System::Windows::Forms::Form and it gives me the error: cannot declare a managed "Pointer" in an unmanaged "Class".
 
I guess you'd need to make your class managed...I've never used .NET in C++ because IMO all of the advantages to C++ revolve around the fact that it is not a managed language. There is really no reason to use .NET with C++ since it actually generates faster exes with C# (I read that somewhere, don't remember where) and using C# is much easier, as it and the .NET framework were more or less designed for each other. If you can, I'd recommend using C# instead of C++ if you want to use .NET. If that would be too much work converting the code, I guess just try to make the rest of your code managed, or maybe someone else can help that has used .NET with C++. Sorry I can't really help.
 
Thanks for the advice, you are right c# is much easier but unfortunately I'm doing this project for my class in which we use Project Builder from Macintosh and c++ with .net is the only equivalent I could find since we're working with multiple .cpp and .h files
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top