VC.NET + MFC 使用 GDI+ DrawLines 画线

VC.NET MFC GDI+ 画线


最近做一个项目 需要 使用GDI+ 的 DrawLines 画线 

MSDN 上给出的实例:

public:
   void DrawLinesPoint( PaintEventArgs^ e )
   {
      // Create pen.
      Pen^ pen = gcnew Pen( Color::Black,3.0f );


      // Create array of points that define lines to draw.
      array<Point>^ points = {Point(10,10),Point(10,100),Point(200,50),Point(250,300)};


      //Draw lines to screen.
      e->Graphics->DrawLines( pen, points );
   }



但是如何动态的添加 Point 数组呢。


这里使用 STL 中的 vector 来存储点,代码如下:


#include <vector>
using namespace std;


vector<PointF*> posVec;


void GISPolyline::AddPoint(CPoint pos)
{
    PointF * posF = new PointF(pos.x,pos.y);
    posVec.push_back(posF);
}


void CXXX::Draw( Graphics& Gr,CRect rect )
{
   Pen m_Pen(Color::Red,2.0f);

if (posVec.size() > 1)
{
int number = posVec.size();
PointF* points = new PointF[number];
int i = 0;

std::vector<PointF*>::iterator ipos = posVec.begin();
for( ; ipos != posVec.end(); ipos++ )
{
points[i].X = (*ipos)->X;
points[i].Y= (*ipos)->Y;
i++;
}

// Draw lines to screen.
Gr.DrawLines(&m_Pen, points, number);

delete[] points;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值