'Why does Visual C++ Designer not work after I added a control to my form?
My wanted to turn on double buffering in a panel, but the only way we could get the DoubleBuffered property to turn on was to create a new class that inherited from System::Windows::Form::Panel, like so:
#include "stdafx.h"
public ref class CPPIConfig: public System::Windows::Forms::Panel
{
public: CPPIConfig()
{
this->DoubleBuffered = true;
}
};
And our form looks like this, now:
#pragma once
#using <system.drawing.dll>
#include "CPPIConfig.h"
[...]
public ref class C3_User_Interface : public System::Windows::Forms::Form
{
[...]
public: CPPIConfig^ pPPI;
[...]
}
void InitializeComponent(void)
{
[...]
this->pPPI = (gcnew CPPIConfig());
[...]
}
[...]
It builds and runs, no problem. However, when I try to view the form in design mode now, I'm getting the following error:
C++ CodeDOM parser error: Line: 144, Column: 15 --- Unknown type 'CPPIConfig'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
My questions:
- Why does design mode not work, even if the code builds and runs? I've tried several clean builds, but that doesn't look to be the issue.
- Is there a way I can set
DoubleBufferedtotruewithout using this method?
Solution 1:[1]
Try moving the control initializing below the suspendlayout. This allows the designer to render correctly without the CodeDOM parse error.
Original was something like
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->lblMessage = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
// lblMessage
this->lblMessage->Location = System::Drawing::Point(12, 230);
//.....
}
New format
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
// lblMessage
this->lblMessage = (gcnew System::Windows::Forms::Label());
this->lblMessage->Location = System::Drawing::Point(12, 230);
//.....
}
Solution 2:[2]
If you Google for your error message, you'll find lots of hits:
C++ CodeDOM parser error: Unknown type 'CPPIConfig'
Please post back if any of these help!
Solution 3:[3]
I had an inherited class from Panel as well. In my case, I had placed this toolbox item in its own C# project with its own namespace. For reasons unknown, the designer worked at first implementation then broke after I attempted to use the inherited class in a second file.
To fix it, I changed the namespace of the C# project to match the consuming projects namespace, as well as explicitly specified it in the designer code:
Project1::InheritedPanel^
instead of simply
InheritedPanel^
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SavageFly |
| Solution 2 | Community |
| Solution 3 | Nabeel |
