Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

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

Using: Visual Studio 2005/08

Languages: C#, Win32 C++, Java, PHP

Posted

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:

  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:

  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

#Include "MsgBox.h"

and in MsgBox I had

#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.

Using: Visual Studio 2005/08

Languages: C#, Win32 C++, Java, PHP

Posted

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 :)

Using: Visual Studio 2005/08

Languages: C#, Win32 C++, Java, PHP

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...