CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

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

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: VC++ 2010 Express IDE eating form designs!?

    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.

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: VC++ 2010 Express IDE eating form designs!?

    Quote Originally Posted by Alex F View Post
    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?
    Attached Files Attached Files
    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.

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: VC++ 2010 Express IDE eating form designs!?

    Yep, I reproduced this in my VS 2010 professional, and couldn't find any solution

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Resolved Re: VC++ 2010 Express IDE eating form designs!?

    [A LOT of time passes...]

    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:

    Code:
    System::Void SplashScreen::SplashScreen_FormClosed(System::Object^  sender, System::Windows::Forms::FormClosedEventArgs^  e)
    {
      stw->Stop();
      safe_cast<Form1 ^>(Owner)->lblElapsed->Text =
        String::Format("Time elapsed while splash screen open: {0} ms", stw->ElapsedMilliseconds);
    }
    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.
    Attached Files Attached Files
    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.

  6. #6
    Join Date
    Jul 2002
    Posts
    2,543

    Re: [RESOLVED] VC++ 2010 Express IDE eating form designs!?

    With their buggy products, they teach us to make a good design...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured