Hi.
Is System.Windows.Forms written only for C#?
If it possible to use it in C++ projects, how to do this?
Printable View
Hi.
Is System.Windows.Forms written only for C#?
If it possible to use it in C++ projects, how to do this?
it is not the WinAPI question!!!
However, yes it is possible, but only if you use managed c++...
OK.
We have a managed C++ project.
Connect to System.Windows.Forms
#using <System.Windows.Forms>
But this not enough!
Something else ??
Why don't you use Search function? There are many examples of this on this site as well as on the others at the Internet!
Code:#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Windows::Forms;
__gc class MyForm : public Form
{
public:
MyForm();
Label* m_label;
Button* m_button;
void Button_OnClick(Object* sender, System::EventArgs* e);
};
MyForm::MyForm()
{
this->Text = "Windows Forms";
this->FormBorderStyle = FormBorderStyle::FixedDialog;
this->ClientSize = System::Drawing::Size(500,500);
m_label = new Label();
m_label->Text="This is Label";
m_label->Size = System::Drawing::Size(200,20);
m_label->Location=Point(10, 10);
m_button = new Button();
m_button->Size = System::Drawing::Size(80, 25);
m_button->Location = Point(60, 35);
m_button->Text = "Click me";
m_button->add_Click(new EventHandler(this, &MyForm::Button_OnClick));
this->Controls->Add(m_label);
this->Controls->Add(m_button);
}
void MyForm::Button_OnClick(Object* sender, System::EventArgs* e)
{
MessageBox::Show("Don't click me again!", "Button");
}
int __stdcall WinMain()
{
Application::Run(new MyForm());
return 0;
}