[C++] Control Properties on Different Forms

3xodus

Freshman
Joined
Dec 26, 2004
Messages
47
Location
Derbyshire, UK
Hi everyone,
I'm new to C++ (2 days :P), and I'm trying to make a function to show a custom MessageBox - I always used to do this in VB6 and VB.NET as imo it looks nicer in certain apps...

Anyway, what I'm trying to do is create a function which can be called, and will show a messagebox with the message of your choice (once it's working I'll add icons and such too).

What I have so far is:
Code:
 private: System::Void MyMessage(System::String * Notice)
 	 {
 		  MsgBox *Message= new MsgBox;
 		//Message->lblNotice->Text = Notice;
 		  Message->ShowDialog();
 	 }
Which could be called like this for example: MyMessage("Hello World!");

My question is about the line that I've commented out. With that line I get the message:
"Cannot access private member declared in class 'prjMsgTest::MsgBox'"

Is it possible to access properties of controls on other forms, as I've failed to do in the code above? If so can anyone give an example? In VB.NET it would simply be
formName.labelName.Text = Notice

TIA for any suggestions :D
 
Thanks for the reply PlausiblyDamp.

I remember reading that thread when I started VB .NET - but it seems either I'm still missing something after reading it through a few more times, or C++ .NET works in a different way.

Trying to pass a string to the forms constructor, as in the example by Bucky in that thread, complains that "function does not take 1 argument". My code for that was:
Code:
   private: System::Void MyMessage(System::String * Notice)
   	 {
   		  MsgBox *Message = new MsgBox(Notice);
   		  Message->ShowDialog();
   	 }

The final example in Bucky's thread, I had some trouble with.

On my Form1, I put #include "MsgBox.h";, and then put this code to call the messagebox:
Code:
   MsgBox *Message = new MsgBox("foo");
   Message->ShowDialog();
At which C++ told me that the first line dosen't accept any arguments.

I have tried getting the info from Form1, by using code in MsgBox - but that failed to build. In Form1 I had
Code:
#Include "MsgBox.h"
and in MsgBox I had
Code:
#Include "Form1.h"
but as soon as I tried to build with #Include "Form1.h" in MsgBox, C++ complained about my referance to MsgBox in Form1 regardless of any code I used to reference the other forms. I think that is probably my fault as it seems like you should be able to do that - like I said I'm only 2 days into C++ so I'm only just starting to get used to it.
 
Heh - I feel so stupid. I found out that the reason that absolutely nothing was working, was that the controls (on the second form) were private. All I had to do was change "private" to "public" and it works fine :o

Thanks anyway for the link Plausibly Damp :)
 
Back
Top