Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Forms in VC++


  • Please log in to reply

#1
megha

megha

    New Member

  • Member
  • Pip
  • 1 posts
I am trying to program an application which has more than one forms. I dont know how to connect two forms... please help!!!
  • 0

Advertisements


#2
StephenL

StephenL

    Member

  • Member
  • PipPip
  • 12 posts
you can declare a public static pointer (to itself) in the first so that it can be accessed from the 2nd form & any other form for that matter. Or you could pass the data you require to the 2nd form when you instantiate it through its constructor.

Corrections:
static pointer I think I used in C# actually so if you're using C++ then just have a member pointer to a Form in the 2nd class & make an overloaded constructor to accept a Form pointer. Then when instantiating the 2nd form pass it the 'this' pointer from the 1st form (as long as you're instantiating it from the 1st form) and assign the passed in pointer to the already created Form pointer member in the 2nd Form. Then you can use the passed in pointer to access all of Form1's members.

Form1:
button_click(---------)
{
Form2 *newForm = new Form2(this);
newForm->Show();
}

class Form2:
{
Form *mForm1;

public Form2()
{
//default constructor
}

public Form2(Form *a1stForm) //new constructor
{
mForm1 = a1stForm;
}


public Form2::AnyMethod()
{
mForm1->Text = "Accessed from Form2";
}


Cheers,
Steve

Edited by StephenL, 25 March 2006 - 02:32 PM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP