-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotnetform.cpp
67 lines (57 loc) · 1.66 KB
/
dotnetform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "dotnetform.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Windows;
using namespace System::Windows::Forms;
ref class MyForm : public Form
{
TextBox ^ textBox = gcnew TextBox();
public:
MyForm()
{
Label ^ label = gcnew Label();
label->Text = "This is .NET form!\nEnter your name";
SuspendLayout();
Controls->Add(label);
textBox->Location = System::Drawing::Point(12, 32);
textBox->Size = System::Drawing::Size(100, 20);
Controls->Add(textBox);
Button ^ okButton = gcnew Button();
okButton->Text = "OK";
okButton->Location = System::Drawing::Point(37, 58);
okButton->Size = System::Drawing::Size(75, 23);
okButton->UseVisualStyleBackColor = true;
Controls->Add(okButton);
okButton->Click += gcnew System::EventHandler(this, &MyForm::OnClick);
this->DialogResult = ::DialogResult::No;
ResumeLayout(false);
PerformLayout();
}
property String ^ name
{
String ^ get()
{
return textBox->Text;
}
}
void OnClick(System::Object ^sender, System::EventArgs ^e);
};
std::string showDotNetForm()
{
MyForm ^ form = gcnew MyForm();
String ^ name = "Anonymous";
if( form->ShowDialog() == ::DialogResult::OK)
{
name = form->name;
}
char * unmanagedName = (char*)(void*)Marshal::StringToHGlobalAnsi( name );
std::string result( unmanagedName );
Marshal::FreeHGlobal( IntPtr( unmanagedName ) );
return result;
}
void MyForm::OnClick(System::Object ^sender, System::EventArgs ^e)
{
DialogResult = ::DialogResult::OK;
Close();
}