Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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