3xodus Posted February 19, 2005 Posted February 19, 2005 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 Quote Using: Visual Studio 2005/08 Languages: C#, Win32 C++, Java, PHP
Administrators PlausiblyDamp Posted February 19, 2005 Administrators Posted February 19, 2005 http://www.xtremedotnettalk.com/showthread.php?t=83092 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
3xodus Posted February 19, 2005 Author Posted February 19, 2005 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. Quote Using: Visual Studio 2005/08 Languages: C#, Win32 C++, Java, PHP
3xodus Posted February 21, 2005 Author Posted February 21, 2005 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 :) Quote Using: Visual Studio 2005/08 Languages: C#, Win32 C++, Java, PHP
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.