在CLR下面基于控制台的应用程序,移植到MFC下基于对话框的模块,在CLR实现的代码如下
{Bitmap^ bitShow=gcnew Bitmap(this->pictureBox1->Width,this->pictureBox1->Height);
Graphics^ g =Graphics::FromImage(bitShow);
int Width =this->pictureBox1->Width;
int Height =this->pictureBox1->Height;
g->FillRectangle(Brushes::White,0,0,Width,Height);
Pen^ p =gcnew Pen(Brushes::Blue,3);
Pen^ p2 =gcnew Pen(Brushes::Black,3);
Pen^ p3 =gcnew Pen(Brushes::Green,3);
Pen^ p4=gcnew Pen(Brushes::Red ,3);
#pragma region 绘制环形轨道
//g->DrawRectangle(p,100,80,230,130);
g->DrawLine(p,100,80,330,80);
g->DrawLine(p,100,210,330,210);
int x=100; //矩形的初始坐标x
int y=80; //矩形的初始坐标y
int width=230; //矩形的宽度
int height=130; //矩形的高度
int y0=y+height/2; //左边圆心(x,y0)
int x0=x+width; //右边圆心(x0,y0)
g->DrawRectangle(p2,x,y0,1,1); //左圆心
g->DrawRectangle(p2,x0,y0,1,1); //右圆心
g->DrawArc(p,35,80,130,130,90,180); //左半圆
g->DrawArc(p,260,80,130,130,90,-180); //右半圆
#pragma endregion
#pragma region 绘制传送机
//红色为出货传送机,绿色为进货传送机
//红色为出货传送机,绿色为进货传送机
g->DrawRectangle(p4,100,230,30,50); //下方传送机
g->DrawRectangle(p3,160,230,30,50); //下方传送机
//上方传送机
g->DrawRectangle(p4,110,10,30,50);
g->DrawRectangle(p3,170,10,30,50);
g->DrawRectangle(p4,210,10,30,50);
g->DrawRectangle(p3,260,10,30,50);
g->DrawRectangle(p4,300,10,30,50);
#pragma endregion
#pragma region 绘制小车
g->DrawRectangle(p4,190,200,20,20);
g->DrawRectangle(p4,300,200,20,20);
// g->DrawRectangle(p4,270,200,20,20);
// g->DrawRectangle(p4,300,200,20,20);
#pragma endregion
Graphics^ gPic =this->pictureBox1->CreateGraphics();
gPic->DrawImage(bitShow,0,0);
}
基于MFC对话框的应用程序,在界面上添加一个命令按钮和一个picture control ,当点击命令按钮时,能在picture控件里面显示图形,如图 望大神指点,在此谢过了。。。由于初学,希望能详细点,谢谢
------解决方案--------------------
直接用GDI绘制就行了。
------解决方案--------------------
MFC 可以不通过托管直接使用gdi+!