I have the following code and Visual Studio C++ reports two errors:
#include "windows.h"
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System::Windows::Forms;
__gc class MyForm : public Form
{
public:
MyForm()
{
Text = "Hello, Windows Forms!";
Button* button = new Button();
button->Text = "Click Me!";
button->Click += new EventHandler(this, button_click);
this->Controls->Add(button);
}
void button_click(Object* sender, EventArgs* e)
{
MessageBox::Show("Ouch!");
}
};
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
Application::Run(new MyForm);
}
and the errors:
error C2061 Syntax Error: Event Args
error C2061 Syntax Error: EventHandler
What should I do to get the code running ?
Thanx in advance.
Add line ‘using namespace System;’
Change ref to button_click as: &MyForm::button_click
Full working code: