【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了Graphic1.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;
//***********使用Win32 API MessageBeep()***************
//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 Graphic1:public Form
{
public:
Graphic1()
{
this->Text = S"Graphic1";
this->StartPosition = FormStartPosition::CenterScreen;
this->Size = System::Drawing::Size(600,360);
Paint += new PaintEventHandler(this,&Graphic1::PaintFunction);
}
void PaintFunction(Object* ps, PaintEventArgs* pe) /*Paint事件处理函数*/
{
if(ps==this) MessageBeep(-1); //ps代表事件源
//定义一种字体
System::Drawing::Font* font1;
font1 = new System::Drawing::Font("宋体",12,FontStyle::Regular,
GraphicsUnit::Millimeter);
//使用 pe->Graphics******************
Graphics* gr1 = pe->Graphics;
//输出文字
gr1->DrawString(S"使用pe->Graphics在此输出。",font1,Brushes::Blue, 0,10);
//在无效矩形区边框上画一个红色矩形
System::Drawing::Rectangle RecClip;
RecClip = pe->get_ClipRectangle();
gr1->DrawRectangle(Pens::Red,
RecClip.Left, RecClip.Top,
RecClip.Right-RecClip.Left-1, RecClip.Bottom-RecClip.Top-1);
//*******使用创建的Graphics***********
Graphics* gr2=CreateGraphics();
//输出文字
gr2->DrawString(S"使用CreateGraphics()。",font1,Brushes::GreenYellow, 0,60);
//颜色、笔、刷子的使用(画线、园、矩形)
Color c1=Color::Aqua;
Color c2=Color::FromArgb(255,0,0,255);
Color c3=Color::FromKnownColor(KnownColor::Beige);
Pen* p1 = new Pen(c1);
Pen* p2 = new Pen(c2);
Pen* p3 = new Pen(c3,6);
gr2->DrawLine(p1,0,120,600,120);
gr2->DrawLine(p2,0,140,600,140);
gr2->DrawLine(p3,0,160,600,160);
gr2->DrawEllipse(p1,100,200,100,100);
gr2->DrawRectangle(p2,250,200,100,100);
gr2->DrawEllipse(p3,400,200,100,100);
gr2->FillEllipse(Brushes::DeepPink, 400,200,100,100);
gr2->Dispose();
//************************************
}
};
//This is the application entry point
void __stdcall WinMain(void)
{
Application::Run(new Graphic1());
}
上一篇:
Main_Form_u.pas
下一篇:
还记得,那年的风车吗?