C++/CLI 创建WinForm程序
2017-09-29 17:21
190 查看
本文演示下用CLR创建一个简单的winform程序,IDE:VS2015
可以参考另一篇文章:http://blog.csdn.net/wcc27857285/article/details/78135314
第一步:
第二步:在头文件文件夹中新增class,选择windows Form
然后查看右侧引用,你会发现多了很多winform专用的dll,VS自动帮我们添加了这些引用
接下来,打开MyForm.cpp,输入代码如下:
至此F5运行,可以看到熟悉的winform界面:
然后,双击右侧MyForm.h,可以看到设计器,然后可以看到左侧的toolbox里面有winform熟悉的各种控件,又可以拖控件了!
在窗体上右键查看View code,可以看到代码如下:
可以参考另一篇文章:http://blog.csdn.net/wcc27857285/article/details/78135314
第一步:
第二步:在头文件文件夹中新增class,选择windows Form
然后查看右侧引用,你会发现多了很多winform专用的dll,VS自动帮我们添加了这些引用
接下来,打开MyForm.cpp,输入代码如下:
#include "MyForm.h" using namespace ClrWinForm; int main(array<System::String^>^args) { Application::EnableVisualStyles(); MyForm^ form = gcnew MyForm(); Application::Run(form); return 0; }
至此F5运行,可以看到熟悉的winform界面:
然后,双击右侧MyForm.h,可以看到设计器,然后可以看到左侧的toolbox里面有winform熟悉的各种控件,又可以拖控件了!
在窗体上右键查看View code,可以看到代码如下:
#pragma once namespace ClrWinForm { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for MyForm /// </summary> public ref class MyForm : public System::Windows::Forms::Form { public: MyForm(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~MyForm() { if (components) { delete components; } } private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; #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->components = gcnew System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = L"MyForm"; this->Padding = System::Windows::Forms::Padding(0); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; } #pragma endregion }; }这是VS自动生成的代码,和传统的winform的desinger.cs中的代码很相似,但是这里使用C++/CLI写的
相关文章推荐
- 在C# WinForm程序中创建控件数组及相应的事件处理
- WinForm程序创建错误日志
- C#winform windows服务程序创建与安装
- c#创建windows服务并在winform程序中用doc命令调用windows服务
- 处理WinForm多线程程序时的陷阱,出现窗口句柄为创建就被访问
- 【PS】使用PowerShell创建WinForm程序(转载)
- c#创建windows服务并在winform程序中用doc命令调用windows服务
- 在C# WinForm程序中创建控件数组及相应的事件处理
- CLI程序内创建全局的托管对象
- winform程序提示“创建窗口句柄时出错”bug
- 在C# WinForm程序中创建控件数组及相应的事件处理
- 一个C++/CLI WinForm程序
- 调用dll给winform程序创建所有用户均可使用的快捷方式
- c#&nbsp;Winform创建安装程序(程序打包…
- C++/CLI 创建WPF程序
- 记事本+.NET framework 4.0 创建第一个c# winform 程序
- <WinForm系列> 1 . 我们如何创建一个WinForm的界面程序?
- C#入门12.1——创建Winform程序
- Qt创建一个电话本界面程序
- java中程序的执行的原理如怎么创建空间,创建对象等