⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winformsmenu.cpp

📁 Visual_C++[1].NET_Bible1 Visual_C++宝典书中的全部源码
💻 CPP
字号:
#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 WinFormsMenuForm : public Form
{
public:
	WinFormsMenuForm();

protected:
  void OnExit (Object* sender, EventArgs *e);
	void OnAbout (Object* sender, EventArgs *e);
};

int __stdcall WinMain()
{   
    Application::Run(new WinFormsMenuForm());
    return 0;
}

WinFormsMenuForm::WinFormsMenuForm()
{
	// Set the titlebar text.
	Text = "Windows Forms Menu Demo";

	// Create a top-level menu for our frame window
	MainMenu* pMenu = new MainMenu();	

	// Add a menu option to the File menu
	MenuItem* pFileMenu = pMenu->MenuItems->Add("File");

	// Add the File menu items now that we have the File item added
  // Notice that the event handlers for these items are also 
  // specified as the items are added to the menu.
	pFileMenu->MenuItems->Add("Exit", new EventHandler(this, &WinFormsMenuForm::OnExit));

	// Add another top-level menu option and it'pstrFileName submenu
	pFileMenu = pMenu->MenuItems->Add("Help");	
	pFileMenu->MenuItems->Add("About...", new EventHandler(this, &WinFormsMenuForm::OnAbout));	

	// Set the current Form object'pstrFileName menu to the newly created menu
	Menu = pMenu;	
}

void WinFormsMenuForm::OnExit(Object *sender, EventArgs *e)
{
  // Simply call the Form object'pstrFileName Close method
	Close();
}

void WinFormsMenuForm::OnAbout(Object *sender, EventArgs *e)
{
	// Display a messagebox as our about box
 MessageBox::Show("Windows Forms Menu Demo, Version 1.0", 
                  "About");
}

⌨️ 快捷键说明

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