//Form1.h 代码:
#pragma once
#include "stdafx.h"
namespace MYFrom1 {
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>
/// Form1 摘要
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//LOG("\nInitializeComponent:%p", this);
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::Button^ button1;
public: System::Windows::Forms::TextBox^ textBox1;
public: System::Windows::Forms::RichTextBox^ richTextBox1;
protected:
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(151, 283);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(200, 72);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(39, 12);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(515, 142);
this->textBox1->TabIndex = 1;
//
// richTextBox1
//
this->richTextBox1->Location = System::Drawing::Point(67, 160);
this->richTextBox1->Name = L"richTextBox1";
this->richTextBox1->Size = System::Drawing::Size(412, 117);
this->richTextBox1->TabIndex = 2;
this->richTextBox1->Text = L"";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(582, 396);
this->Controls->Add(this->richTextBox1);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Name = L"MyForm";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e);
};
}
//Form1.cpp代码:
#pragma once
#include "stdafx.h"
#include "gcroot.h" //VS2015以下版本要引用这个头文件。
#include "Form1.h"
using namespace MYFrom1 ;
gcroot<MYFrom1::MyForm^> vMySubFrm; //#include "gcroot.h" //VS2015以下版本要引用这个头文件。
System::Void MyForm::button1_Click(System::Object^ sender, System::EventArgs^ e)
{
vMySubFrm = this;
this->richTextBox1->AppendText("\nHello World OK");
};
//CMyClass.h代码:
#pragma once
#include "stdafx.h"
class CMyClass
{
public :
CMyXMdApi(){}
~CMyXMdApi(){}
void pro1();
};
//CMyClass.cpp代码:
#pragma once
#include "stdafx.h"
#include "CMyClass.h"
#include "Form1.h"
using namespace MYFrom1 ;
extern gcroot<MYFrom1::MyForm^> vMySubFrm;
void CMyClass::pro1()
{
System::String ^ str = "\nHello World\n";
vMySubFrm->richTextBox1->AppendText(str);
};