我用PolyPolyline函数画线时,画出来的线好嫩,如果打印机的碳粉少些就打的不清楚,请问这个函数是用什么画的线啊,是用的TPrinter.Canvas还是用如画蚂蚁线那样是象素画的呢?很急啊,请英雄指教啊!

解决方案 »

  1.   

    新建一个Pen对象, 然后设定你想要的宽度.
    试试这个看:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Dc : HDC;
      Pt : Array [0..2] of TPoint ;
      Count1, count2 : Integer;
      Brush : TLogbrush;
      hBrush,hPen : LongInt;
      Pen : TLOGPEN;
      PenPoint : TPoint;
    begin
      pt[0].x := 100;
      pt[0].y := 100;
      pt[1].x := 50;
      pt[1].y := 150;
      pt[2].x := 150;
      pt[2].y := 150;
      Dc := GetDC(handle);
      Brush.lbStyle := BS_SOLID;
      Brush.lbColor := clGreen;
      Brush.lbHatch := 0;
      hBrush := SelectObject(Dc,CreateBrushIndirect(Brush));
      PenPoint.x := 2;     // Your pen width here.
      PenPoint.y := 0;
      Pen.lopnStyle := PS_SOLID;
      Pen.lopnWidth := PenPoint;
      Pen.lopnColor := clRed;
      hPen := SelectObject(Dc,CreatePenIndirect(Pen));  // bind your current canvas.
      Polygon(DC,pt,3);     // replace with your PolyPolyline functions.
      SelectObject(DC, hPen);
      SelectObject(DC, hBrush);end;
      

  2.   

    请大家看看我这段代码:drect:=rect(PageRect.Left,Amountprint,PageRect.Left+round(0.1*(PageRect.Right-PageRect.Left)),Amountprint+2*textheight);
    drawtext(pp_pz.Printer.Canvas.handle,pchar(inttostr(p_year)+'年'),length(inttostr(p_year)+'年'),drect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);
    addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);srect:=rect(PageRect.Left,drect.Bottom,round(0.5*(drect.right-drect.left)+drect.Left),drect.Bottom+2*textheight);
        drawtext(pp_pz.Printer.Canvas.handle,pchar('月'),length('月'),srect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);    addpolyline([srect.left,srect.top,srect.right,srect.top,srect.right,srect.bottom,srect.left,srect.bottom,srect.left,srect.top]);
        srect:=rect(srect.Right,srect.Top,round(0.5*(drect.right-drect.left)+srect.Right),srect.Bottom);    drawtext(pp_pz.Printer.Canvas.handle,pchar('日'),length('日'),srect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);
        addpolyline([srect.left,srect.top,srect.right,srect.top,srect.right,srect.bottom,srect.left,srect.bottom,srect.left,srect.top]);
        drect:=rect(drect.right,drect.Top,drect.right+round(0.08*(PageRect.Right-PageRect.Left)),srect.Bottom);
        drawtext(pp_pz.Printer.Canvas.handle,pchar('凭证号'),length('凭证号'),drect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);
        addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
        drect:=rect(drect.right,drect.Top,drect.right+round(0.29*(PageRect.Right-PageRect.Left)),srect.Bottom);
        drawtext(pp_pz.Printer.Canvas.handle,pchar('摘  要'),length('摘  要'),drect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);    addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom]);
        drect:=rect(drect.right,drect.Top,drect.right+round(0.16*(PageRect.Right-PageRect.Left)),srect.Bottom);
        drawtext(pp_pz.Printer.Canvas.handle,pchar('借方金额'),length('借方金额'),drect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);    addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
        drect:=rect(drect.right,drect.Top,drect.right+round(0.16*(PageRect.Right-PageRect.Left)),srect.Bottom);
        addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
        drawtext(pp_pz.Printer.Canvas.handle,pchar('贷方金额'),length('贷方金额'),drect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);    addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom]);
        drect:=rect(drect.right,drect.Top,drect.right+round(0.03*(PageRect.Right-PageRect.Left)),srect.Bottom);
        addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);    jrect:=rect(drect.left,drect.Top+round((drect.bottom-drect.top-2*textheight)*0.5),drect.right,drect.Bottom);
        drawtext(pp_pz.Printer.Canvas.handle,pchar('方向'),length('方向'),jrect,DT_center or  DT_wordbreak);    addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
        drect:=rect(drect.right,drect.Top,drect.right+round(0.18*(PageRect.Right-PageRect.Left)),srect.Bottom);
        addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom,drect.left,drect.top]);
        drawtext(pp_pz.Printer.Canvas.handle,pchar('期末余额'),length('期末余额'),drect,DT_center or  DT_WORDBREAK or DT_VCENTER or DT_SINGLELINE);    addpolyline([drect.left,drect.top,drect.right,drect.top,drect.right,drect.bottom,drect.left,drect.bottom]);
        //
        pp_pz.printer.Canvas.pen.Width:=4;
    //    pp_pz.printer.Canvas.pen.Style
        PolyPolyline(pp_pz.Printer.Canvas.Handle,PolyPolyPoints.List^,PolyLengths.List^,PolyLengths.Count);----------------------------------------------------------
    说明:楼上的,我不想换其他函数,因为我觉得PolyPolyline挺好的,就是怎么把线画粗来就行了!
      

  3.   

    上面只是一个简单例子, 说明如何把它的Pen设粗一点.
    replace with your PolyPolyline functions是指用你的PolyPolyline 来代替了我这一句试试看的意思.
    1.你要用下面代码来新建一个宽为2的Pen.与你的输入设备相联接
      PenPoint.x := 2;     // 你想要的宽度.
      PenPoint.y := 0;
      Pen.lopnStyle := PS_SOLID;
      Pen.lopnWidth := PenPoint;
      Pen.lopnColor := clRed;
      hPen := SelectObject(Dc,CreatePenIndirect(Pen));  // 邦定Pen到你的输出设备.
    2. 直接用你的PolyPolyline函数来进行画多边形.
    ......
    PolyPolyline(pp_pz.Printer.Canvas.Handle,PolyPolyPoints.List^,PolyLengths.List^,PolyLengths.Count);
    3.画完或打印完后再还原以前的Pen.
      

  4.   

    3.画完或打印完后再还原以前的Pen.
    SelectObject(DC, hPen);
      

  5.   

    具体到你上面的程序, DC改为pp_pz.Printer.Canvas.Handle
      

  6.   

    谢谢Wnyu(西门吹水) 的解答,我去试试看啊!
      

  7.   

    Wnyu(西门吹水):   好象没有用呢,我测过你那个例子是可以的,是不是PolyPolyline不可以而Polygon可以你说的办法呢?你去试试PolyPolyline函数好吗?
      

  8.   

    行呀, 我忘了PolyPolyline的具体用法,不过还是能看出一条很粗的线. 第一个程序改一下为:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Dc : HDC;
      Pt : Array [0..2] of TPoint ;
      Count1, count2 : Integer;
      Brush : TLogbrush;
      hBrush,hPen : LongInt;
      Pen : TLOGPEN;
      PenPoint : TPoint;
      dd : Integer;
    begin
      pt[0].x := 100;
      pt[0].y := 100;
      pt[1].x := 50;
      pt[1].y := 150;
      pt[2].x := 150;
      pt[2].y := 150;
      Dc := GetDC(handle);
      Brush.lbStyle := BS_SOLID;
      Brush.lbColor := clGreen;
      Brush.lbHatch := 0;
      hBrush := SelectObject(Dc,CreateBrushIndirect(Brush));
      PenPoint.x := 10;     // Your pen width here.
      PenPoint.y := 0;
      Pen.lopnStyle := PS_SOLID;
      Pen.lopnWidth := PenPoint;
      Pen.lopnColor := clRed;
      hPen := SelectObject(Dc,CreatePenIndirect(Pen));  // bind your current canvas.
    //  Polygon(DC,pt,3);     // replace with your PolyPolyline functions.
      dd := 3;
      PolyPolyline(DC,pt,dd, 3);
      SelectObject(DC, hPen);
      SelectObject(DC, hBrush);end;
      

  9.   

    Wnyu(西门吹水),你上面的例子好象不行啊,你试试看啊~~~!