15,890,690 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by DaveLock (Top 4 by date)
DaveLock
14-Mar-11 6:15am
View
It works!
FYI, as typed it had 4 build errors with:
Form::Instance->label1->Text = L"Simple singleton";
But it builds & worked when I changed it to:
Form1::Instance->label1->Text = L"Simple singleton";
That is exactly what I was wanting. Thank you so much for your help & patience, it is very much appreciated. Now, as you said, the properties can be changed from any code file that includes the Form.h. Beautiful!
Woohoo!
Dave.
DaveLock
13-Mar-11 4:39am
View
Update 2:
That handler code only builds for me if it is located WITHIN THE CLASS, which is WITHIN THE HEADER FILE.
I sincerely appreciate your help, but the solution you are giving me I stated in the 2nd paragraph of my original question, that I have already done. I want to achieve that same result, but WITHIN A FUNCTION IN THE SampleWinforms.cpp FILE (such as fnTest is). Is this possible?
I'm starting to think that maybe VC++ sucks at WinForms development. Hmmm.
Dave.
DaveLock
12-Mar-11 21:40pm
View
UpdateThat builds & runs ok, but doesn't do what I was asking for.
Firstly, it seems to me that this way the text is being set BEFORE the form opens. I want to change the text of label1 on the form that is ALREADY OPEN (now called mainForm), whilst it is open. I don't want to create new forms with the text in label1 already set.
Secondly, putting the code in the event handler worked for me right from the start, but as I said in my 2nd para of the question above, that means all of the code is in the header files, because the handlers are in the class which is in the form's header file.
And thirdly, the button just creates new forms, so the more it is clicked, the more forms are opened.
I like the way you declared mainForm as a Form1 object before putting that into Application::Run(). Is there any way to make that declaration of the mainForm object, or a pointer to the mainForm object, global throughout that cpp file? Couldn't I then use that pointer as my reference to change the text from a function in the cpp file? Something like 'ptr_mainForm->label1->Text = L"some text";', where 'ptr_mainForm' is the global pointer to the mainForm object.
Thanks for your help,
Dave.
DaveLock
12-Mar-11 7:51am
View
Thanks so much for your reply, Espen, much appreciated.
It bulds ok, but at runtime throws an error at the Application::Run(mainForm); line.
"An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead."
If I just comment out the Application::Run(mainForm); line, or if I also try the line you commented should work, then it builds & runs without error, but doesn't change the value of the label1 on Form1 (it does nothing).
Dave.