formsampleplusbutton.cpp

来自「C++ Source code from a tutorial」· C++ 代码 · 共 44 行

CPP
44
字号
// This is the main project file for VC++ application project 
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#using <System.DLL>
#using <System.Windows.Forms.DLL>
#using <System.Drawing.DLL>

#include <tchar.h>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

__gc class MyFormClass : public Form {
protected:
    Button *button;
public:
    void AddControls() {
        button = new Button;
        button->Text = "Click!";
        button->Left = 25;
        button->Top = 25;
        button->Click += new EventHandler(
            this, MyFormClass::Click);
        this->Controls->Add(button);
    }
    void Click(Object* sender, EventArgs* e)
    {
        MessageBox::Show("Click!");
    }
};

// This is the entry point for this application
int _tmain(void)
{
    MyFormClass *MyForm = new MyFormClass();
    MyForm->AddControls();
    MyForm->ShowDialog();
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?