【VC开源代码栏目提醒】:本文主要为网学会员提供Event2.cpp,希望对需要Event2.cpp网友有所帮助,学习一下!
// 这是使用应用程序向导生成的 VC++
// 应用程序项目的主项目文件。
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <system.drawing.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
//******************************************************
//For Using Win32 API Function : MessageBeep()
using namespace System::Runtime::InteropServices;
[DllImportAttribute("User32.dll",CharSet=CharSet::Auto)]
extern "C" bool MessageBeep(UInt32 uType);
//******************************************************
__gc class WFormEvent2:public Form
{
public:
WFormEvent2()
{
Text/*属性*/=S"Form 类的事件";
Size/*属性*/=System::Drawing::Size(600,400);
StartPosition /*属性*/= FormStartPosition::CenterScreen;/*枚举变量*/
//******************************************************************************
MouseDown/*事件*/ +=new MouseEventHandler(this,&WFormEvent2::MouseDownFunction);
MouseUp /*事件*/ +=new MouseEventHandler(this,&WFormEvent2::MouseUpFunction);
MouseMove/*事件*/ +=new MouseEventHandler(this,&WFormEvent2::MouseMoveFunction);
MouseEnter +=new EventHandler(this,&WFormEvent2::MouseEnterFunction);
MouseLeave +=new EventHandler(this,&WFormEvent2::MouseLeaveFunction);
MouseHover +=new EventHandler(this,&WFormEvent2::MouseHoverFunction);
KeyDown +=new KeyEventHandler(this,&WFormEvent2::KeyDownFunction);
KeyUp +=new KeyEventHandler(this,&WFormEvent2::KeyUpFunction);
KeyPress +=new KeyPressEventHandler(this,&WFormEvent2::KeyPressFunction);
Paint +=new PaintEventHandler(this,&WFormEvent2::PaintFunction);
SizeChanged +=new EventHandler(this,&WFormEvent2::SizeChangedFunction);
LostFocus +=new EventHandler(this,&WFormEvent2::LostFocusFunction);
//******************************************************************************
}
private:
//***********************************************************************************
void MouseDownFunction(Object* ps, MouseEventArgs* pe) /*MouseDown事件处理函数*/
{
if(pe->Button==MouseButtons::Left)
{
//MessageBox::Show(S"当鼠标左键在窗口用户区按下时弹出的消息框");
}
}
void MouseUpFunction(Object* ps, MouseEventArgs* pe) /*MouseUp事件处理函数*/
{
//MessageBeep(-1);
}
void MouseMoveFunction(Object* ps, MouseEventArgs* pe) /*MouseMove事件处理函数*/
{
//MessageBeep(-1);
}
//***********************************************************************************
void MouseEnterFunction(Object* ps, EventArgs* pe) /*MouseEnter事件处理函数*/
{
}
void MouseLeaveFunction(Object* ps, EventArgs* pe) /*MouseLeave事件处理函数*/
{
}
void MouseHoverFunction(Object* ps, EventArgs* pe) /*MouseHover事件处理函数*/
{
}
//***********************************************************************************
void KeyDownFunction(Object* ps, KeyEventArgs* pe) /*KeyDown事件处理函数*/
{
}
void KeyUpFunction(Object* ps, KeyEventArgs* pe) /*KeyUp事件处理函数*/
{
}
void KeyPressFunction(Object* ps, KeyPressEventArgs* pe)/*KeyPress事件处理函数*/
{ //MessageBeep(-1);
}
//***********************************************************************************
void PaintFunction(Object* ps, PaintEventArgs* pe) /*Paint事件处理函数*/
{ MessageBeep(-1);
//Get Graphics
Graphics* gr = pe->Graphics;
//Draw text
System::Drawing::Font* font1
=new System::Drawing::Font("宋体",8,FontStyle::Regular,GraphicsUnit::Millimeter);
gr->DrawString(S"本例程演示12种事件的产生及处理。",font1,Brushes::Blue, 0,10);
}
void SizeChangedFunction(Object* ps, EventArgs* pe) /*SizeChanged事件处理函数*/
{
}
void LostFocusFunction(Object* ps, EventArgs* pe) /*LostFocus事件处理函数*/
{ //MessageBeep(-1);
}
};
//This is the application entry point
void __stdcall WinMain(void)
{
Application::Run(new WFormEvent2());
}
上一篇:
Event1.cpp
下一篇:
临床前药物安全性评价中毒性病理学新技术的应用