将控件添加到窗体后,为什么Visual C ++ Designer无法正常工作? [英] Why does Visual C++ Designer not work after I added a control to my form?

查看:125
本文介绍了将控件添加到窗体后,为什么Visual C ++ Designer无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在面板中打开双缓冲,但是我们可以打开 DoubleBuffered 属性的唯一方法是创建一个继承自 System :: Windows的新类.:: Form :: Panel ,就像这样:

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;
        }
};

现在我们的表单如下:

#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解析器错误:行:144,列:15 ---未知类型'CPPIConfig'.请确保已引用包含该类型的程序集.如果此类型是开发项目的一部分,请确保已成功构建该项目.

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.

我的问题:

  1. 即使代码已生成并运行,为什么设计模式也不起作用?我已经尝试了几个干净的版本,但这似乎不是问题.
  2. 有没有一种方法可以在不使用此方法的情况下将 DoubleBuffered 设置为 true ?

推荐答案

这里最大的麻烦实际上是由于托管代码与非托管代码的混合.我去了 MSDN来阅读,但是结果是这样的: Visual Studio无法在此上下文中处理我的 CPPIConfig 类,因为它是非托管/本机代码.

The big hangup here really stems from my mixture of managed vs. unmanaged code. I went to MSDN to read more about it, but the upshot is this: Visual Studio can't handle my CPPIConfig class within this context because it's unmanaged/native code.

从为

Windows窗体设计器无法在混合模式EXE上进行反映.确保使用/clr:pure进行编译,或将任何需要设计时支持的类(例如,表单上的组件和控件)移到类库项目中.

The Windows Forms Designer cannot reflect on mixed-mode EXEs. Make sure you compile with /clr:pure or move any class that require design time support (e.g. the components and controls on the form) to a class library project.

反射,此MSDN页面指向out ,这是设计"视图用于在IDE中呈现表单的功能.简而言之,这就是反思:

Reflection, as this MSDN page points out, is what the Design view is using to render the Form within the IDE. In a few words, this is what reflection is:

Reflection允许在运行时检查已知数据类型.反射允许枚举给定程序集中的数据类型,并且可以发现给定类或值类型的成员.不管在编译时是已知类型还是引用类型,这都是正确的.这使反射成为开发和代码管理工具的有用功能.

Reflection allows known data types to be inspected at runtime. Reflection allows the enumeration of data types in a given assembly, and the members of a given class or value type can be discovered. This is true regardless of whether the type was known or referenced at compile time. This makes reflection a useful feature for development and code management tools.

啊.这开始变得有意义了.

Ahh. This is starting to make sense.

据我所知,有两种方法可以解决此问题.

There's two ways to fix this problem, as far as I can tell.

在项目属性中使用/clr:pure .这将更改项目的Common Language Runtime支持.来自此MSDN页面:

纯程序集(与/clr:pure编译)可以包含本机和托管数据类型,但只能包含托管函数.与混合程序集一样,纯程序集允许通过P/Invoke与本机DLL互操作(请参阅在C ++中使用显式PInvoke(DllImport属性)),但C ++ Interop功能不可用.此外,纯程序集无法导出可从本机函数调用的函数,因为纯程序集中的入口点使用__clrcall调用约定.

Pure assemblies (compiled with /clr:pure) can contain both native and managed data types, but only managed functions. Like mixed assemblies, pure assemblies allow interop with native DLLs through P/Invoke (see Using Explicit PInvoke in C++ (DllImport Attribute)), but C++ Interop features are not available. Moreover, pure assemblies cannot export functions that are callable from native functions because entry points in a pure assembly use the __clrcall calling convention.

创建一个类库项目.作为另一个答案,如果我将文件移动到类库项目中并以这种方式引用,则不会出现此问题.据我了解,它将成为 CPPIConfig 托管代码.

Create a class library project. As the other answer suggested, if I move the files to a class library project and reference it that way, I wouldn't see this problem. As I understand it, it would make CPPIConfig managed code.

最终,结构上的限制使得这两个选项都不可行,为了节省时间,我们决定暂时放弃面板上的双重缓冲.哦,好吧,至少我对这种环境了解更多!

Ultimately, structural limitations make neither of those options viable, and in the interest of time, we've decided to forego double buffering on the panel for now. Oh well, at least I learned more about this environment!

这篇关于将控件添加到窗体后,为什么Visual C ++ Designer无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆