tags:

views:

158

answers:

1

Hi,

how I can access controls of Form class from another simple class

Lets say I have create new clr (c++ .net 2008) windows application, & add a lable1 on it, (Form1.cpp & Form1.h created by default having namaspace tmp_beginInvoke_c)

then I create a new b.h file & add a simple reference class b. like code below,

#include "Form1.h"

namespace tmp_beginInvoke_c_B {

 //using namespace tmp_beginInvoke_c;  //{error C2871: 'tmp_beginInvoke_c' : a namespace with this name does not exist,} namespace of Form1 in my project
 using namespace System;
 using namespace System::ComponentModel;

 public ref class b
 {
 public: 
  b(void)
  {

  }


  b(Form1^% guiForm)
  {
   //guiForm->ChangeLabel();
   //this->frm = gcnew Form1();
   this->frm = guiForm;
   this->frm->ChangeLabel();

  }

  int i;
  Form1 ^frm;

 };

}

I also add following in Form1.h

  1. #include "b.h"
  2. using namespace tmp_beginInvoke_c_B;
  3. b^ obj = gcnew b(); // this line in constructure.

raising build error :-(

My target:- I want to pass reference of Form1 created instance to all b class object, b class object will call a function of form1 class randomly on event base.

if I say ore accuretely b class object will call beginInvoke of control on Form1.
something like
Thread^ t = gcnew Thread(gcnew ThreadStart((frm,&tmp_beginInvoke_c::Form1::ChangeLabel)); //which will call beginInvike of control

A: 

As probably everybody before I do not understand the question.

But I would advise to separate declaration from implementation. Both classes reference each other so you probably need to use forward declaration for one of them, e.g. ref class b; in Form1.h. But you cannot access any member of this class including constructor before the real declaration is known.

rotti2