[RESOLVED] VC++ 2010 Express IDE eating form designs!?
Since I'm using VC++ 2010 Express I've twice experienced the phenomenon that suddenly the two forms of an app containing two forms looked exactly the same in the Forms Designer (editor tab titled "Form1.h [Design]" e.g.). Luckily this only happened to really unimportant test projects so far, otherwise I'd certainly have attached the blazing red smiley to this post instead of that lilac one. Incidentally, it happened to two projects containing exactly two forms up to now. Of course it's impossible to happen to a project having only a single form, but I don't see any compelling reason why it should be impossible with projects containing more than two forms.
I couldn't yet spot the files that contain this visual form design. Originally I supposed the .resX files to hold this data, but they apparently only hold miscellaneous information on the forms like the position of objects on the Forms Designer's tray in the project I examined. The .h file itself (in code view instead of design view) seems to be intact, BTW, and I think it might be possible to reconstruct the form's design view from the information in InitializeComponent() if only I found a way to force the IDE to do that.
What I tried so far to no avail: cleaning the project and selecting "Update managed resources" from the .h file's context menu in Project Explorer.
Any comments?
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Everything that Windows Forms designer needs is in Form1.h:
Code:
private: System::Windows::Forms::Button^ button1;
// other class members ...
#pragma region Windows Form Designer generated code
// InitializeComponent function
...
#pragma endregion
When designer is opened, it scans h-file and shows the form in design mode. Changes in design mode are written to h-file. Working with h-file, don't corrupt designer-generated code. This really sucks - in C# they did partial classes to solve this problem, and designer has its own file.
Everything that Windows Forms designer needs is in Form1.h:
[...]
When designer is opened, it scans h-file and shows the form in design mode. Changes in design mode are written to h-file.
It would be nice if that were the whole story. I have the strong impression, though, that the design shown in the Forms Designer window gets cached somewhere. I suppose all I'd need to do would be to delete the cache in order to force the IDE to rebuild it, if only I'd know how to do that...
I have attached the only project I have at the time that suffers from that problem. As already said, cleaning the project (which I did of course before uploading it) didn't help.
Working with h-file, don't corrupt designer-generated code.
I once tried to change that code intentionally, still keeping it valid C++/CLI source code of course. I didn't get far with that though; don't remember anymore whether it was the IDE or the compiler that stopped me. Obviously this region is checksummed somewhere.
[...] in C# they did partial classes to solve this problem, and designer has its own file.
AFAIK the design usually is XAML-based in C# and I can't imagine how that would naturally mix with C# source code anyway. Or does that apply to C#-based Windows Forms apps as well?
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Merely by chance, I just happened to figure out not only what caused the problem here, but also how to easily fix it.
It was the forward declaration of Form1 in SplashScreen.h that messed up the Forms Designer:
Code:
ref class Form1;
This was only required anyway to declare the Form1 ^pOwner; member variable of the splash screen class. And I can get rid of that variable entirely and use the cast splash screen form's Owner property instead:
Obviously, I just failed to properly recall that property when I wrote that code.
I have attached the fixed project to this post for reference.
I figure, if one would really, really need a forward declaration of a form class in another form class' header file, they could place that forward declaration in an extra .h file created solely for that purpose and include it. This would probably not mess up the Designer.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.