Passing a handle from the main form to other forms? Windows Forms (C++/CLI)

Viewed 22

When I open Form2 (from Form1) I wish I have a handle that point to Form1, so I can access its public properties and call its public functions (from Form2). Is it possible?

For example, both forms - Form1 and Form2 - belong to the same namespace "appDesk".

// Form1.h

#include "Form2.h"
namespace appDesk {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;

public ref class winMain : public System::Windows::Forms::Form
{
public:
    array<Int32>^ InitialPosition = gcnew array<Int32>(4);

    winMain(void)
    {
        InitializeComponent();
    }

// Clicked button event (on Form1)

Form2^ SecundaryForm = gcnew Form2(this)

// "Form2.h"

namespace appDesk {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;

public ref class Form2: public System::Windows::Forms::Form
{
public:
    Form2(appDesk::Form1^ PrimaryForm)
    {
        InitializeComponent();
    }

VS show no alert, but when I try to compile show an error "C2039 - 'Form1': is not a member of 'appDesk'". If a include "Form1.h" (on "Form2.h") VS show an error "C2065 - 'Form2': undeclared identifier".

0 Answers
Related