如何在c++ /CLI中使用设计器继承现有的Windows窗体控件
How to Inherit from Existing Windows Forms Controls in C++/CLI with Designer
我需要在visual studio 2012中的c++/cli中自定义DataGridView类,可以在设计器视图中使用。
我创建了一个默认的clr用户继承System::Windows::Forms::UserControl,并将UserControl更改为DataGridView,但它在c++中不起作用。它在c#中工作。[1]
没有从头编写的代码被设计人员识别。[2]
似乎我必须把DataGridView在类中,但我将不得不访问其成员,如grid->view->GetName..而不是grid->GetName..现在。而且它也不会被模式化,而CLR在所有这些奇怪的语法之后本来是打算这样做的。
[1] http://msdn.microsoft.com/en-us/library/7h62478z.aspx[2]使用Windows窗体设计器添加用户控件
按照下面的步骤操作Visual Studio 2010。这些步骤应该也适用于Visual Studio 2012。
- 创建一个新的 visualc++ -> CLR -> ClassLibrary项目(例如CustomDataGridView)
- 添加System.Windows。表单引用到项目
-
将CustomDataGridView.h的内容更改为:
#pragma once using namespace System; using namespace System::Windows::Forms; namespace CustomDataGridView { public ref class MyDataGridView : DataGridView { // TODO: You can include your custom behavior here. }; }
编译你的项目 - 用Form打开/创建一个项目,然后打开Form
- 右键进入工具箱,选择 choose Items…
- 浏览CustomDataGridView.dll并加载自定义控件 现在MyDataGridView应该列在工具箱中,你可以通过拖放将它放到表单中
相关文章:
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 在编译时,C++项目抛出错误 C2228,这是预期的,因为控件在运行时未达到该点
- 如何更改窗体上所有控件的标题?[C++生成器]
- 双击更改 mfc 中列表控件中的行的颜色
- 派生的 wxPanel 控件如何访问其中包含 wxDialog 中的数据?
- 如何从代码本身向 wxwidgets 中的文本控件插入字符?
- 如何在MFC中的静态文本控件上插入图标?
- 我的主窗口在创建时或单击更新区域时是否会收到编辑控件?
- 如何在Qt C++中向自定义控件添加属性?
- C/C++ 检测双击 TVItem 的常用控件
- 从C++标头中导入常量而不是硬编码它们:扩展 .net 控件?
- 控件不会在选择函数旁边移动
- MFC:我们能否扩展CEditView中存在的CEdit控件类行为
- 通过嵌入式 IWebBrowser2 控件中的链接打开 youtube 搜索失败
- 查找素数:错误:控件到达非void函数的末尾
- C++ 获取"控件可能会到达约翰逊-特罗特代码上的非空函数的末尾
- C++WIN32-将RTF数据加载到Rich Edit控件
- 继承的CEdit控件(用于垂直居中的文本)的行为很奇怪
- 如何在c++ /CLI中使用设计器继承现有的Windows窗体控件