直线显示和打印

来源:互联网 发布:说话的艺术 知乎 编辑:程序博客网 时间:2024/05/01 13:18

()画直线

画笔定义:Pen  pen=Pen(clr);Pen pen=Pen(clr,width);

     可以通过Width 来定义画笔的宽度.

         pen.Width=2;

       画笔的最小宽度是1,既是说pen.Width=0;而实际画出来的线条还是1.

 Graphics. DrawLine(pen,0,0,x,y);是画包括,(0,0)(x,y)在内的一些点.对于Win32API画线时不包括(x,y)

(二)  打印

(二)  打印

PrintDocument对象.

DocumentName 属性是文本字符串,是文本输入到假脱打印机对话筐中标识这一任务的文字.

PrintDocumentOnPrintPage(Object obj,PrintPageEventArgs  e)事件中对具体打印进行设置

PrintPageEventArgsHasMorePagetrue 表示打印多页,false表示打印单页.

打印机的整个页面由三个不同区域定义.

 1,整个页面大小由PrintPageEventArgsPageBounds属性提供

 2,页面可打印区.等于整个页面去掉打印头,不能到达的页边空白. GraphicsVisibleClipBounds

   属性提供了页面可打印区的大小.

 3,第三区是页面上4个角保留1英寸的打印空白.可以通过PrintPageEventArgsMarginBounds属性得到.

using System;

using   System.Drawing ;

using System.Drawing.Printing ;

using  System.Windows.Forms ;

namespace WindowsProgram

{    class PrintTableForm:Form

     {    static void Main(string[] args)

         {

              Application.Run(new PrintTableForm());

         }

         public  PrintTableForm()

         {  Text="Print  Table Form";

           BackColor=SystemColors.Window ;

            ForeColor=SystemColors.WindowText;

            ResizeRedraw=true;         

         }

         protected override void OnPaint(PaintEventArgs e)

         {

              DoPage(e.Graphics,ForeColor,ClientSize.Width,ClientSize.Height);

         }

         void  PrintDocumentOnPrintPage(Object obj,PrintPageEventArgs  e)

         {   Graphics grs=e.Graphics ;

              SizeF sizef=grs.VisibleClipBounds.Size;

              DoPage(grs,ForeColor,(int)sizef.Width,(int)sizef.Height);

         }

         protected override  void OnClick(EventArgs ea)

         {    PrintDocument  pdt=new PrintDocument();

              pdt.DocumentName=Text;

              pdt.PrintPage +=new PrintPageEventHandler(PrintDocumentOnPrintPage);

              pdt.Print();

         }

         protected  virtual void  DoPage(Graphics  grs,Color clr,int cx,int cy)

         {  Pen  pen=new Pen(clr);

            grs.DrawLine(pen,0,0,cx-1,cy-1);               

            grs.DrawLine(pen,cx-1,0,0,cy-1);             

         }

     }

}

 

 

 

 

(三)  图象保真.

Graphics类的SmoothingMode线条保真.其确省是无图象保真.当设置图象保真后,远看线条平滑滑,近看线条有些乱.

Graphics类的PixelOffsetMode增强保真,既象素偏移.,设置后将向上偏移半个象素.

:

using System;

using   System.Drawing ;

using System.Drawing.Printing ;

using  System.Windows.Forms ;

using System.Drawing.Drawing2D ;

namespace WindowsProgram

{        class AntiAlies:Form

     {    static void Main(string[] args)

         {

              Application.Run(new AntiAlies());

         }

         public  AntiAlies()

         {    Text="Anti Alins";

              BackColor=SystemColors.Window ;

              ForeColor=SystemColors.WindowText;

              ResizeRedraw=true;       

         }

         protected override void OnPaint(PaintEventArgs e)

         {    Graphics  grs=e.Graphics;

              Pen  pen=new Pen(ForeColor);             

              grs.SmoothingMode =SmoothingMode.HighQuality;

              grs.PixelOffsetMode=PixelOffsetMode.HighQuality ;

              grs.DrawLine(pen,2,2,18,10);        }

     }} 

 

 

 

 

(三)  图象保真.

Graphics类的SmoothingMode线条保真.其确省是无图象保真.当设置图象保真后,远看线条平滑滑,近看线条有些乱.

Graphics类的PixelOffsetMode增强保真,既象素偏移.,设置后将向上偏移半个象素.

:

using System;

using   System.Drawing ;

using System.Drawing.Printing ;

using  System.Windows.Forms ;

using System.Drawing.Drawing2D ;

namespace WindowsProgram

{        class AntiAlies:Form

     {    static void Main(string[] args)

         {

              Application.Run(new AntiAlies());

         }

         public  AntiAlies()

         {    Text="Anti Alins";

              BackColor=SystemColors.Window ;

              ForeColor=SystemColors.WindowText;

              ResizeRedraw=true;       

         }

         protected override void OnPaint(PaintEventArgs e)

         {    Graphics  grs=e.Graphics;

              Pen  pen=new Pen(ForeColor);             

              grs.SmoothingMode =SmoothingMode.HighQuality;

              grs.PixelOffsetMode=PixelOffsetMode.HighQuality ;

              grs.DrawLine(pen,2,2,18,10);        }

     }} 

(三)  多重连接直线.

  使用  Graphics.DrawLines(new Pen(clr),pt);

using System;
using   System.Drawing ;
using System.Drawing.Printing ;
using  System.Windows.Forms ;
namespace WindowsProgram
{
  class BoxingPoint:PrintTableForm
 {
   static void Main(string[] args)
  {
   Application.Run(new BoxingPoint());
  }
  public  BoxingPoint()
  {
   Text="Boxing  Point  the  Clinet";
   
  }
  protected  override void  DoPage(Graphics  grs,Color clr,int cx,int cy)
  {
   Point[] pt={new Point(0,0), new Point(cx-1,0),new Point(cx-1,cy-1), new Point(0,cy-1),new Point(0,0)};
   
   grs.DrawLines(new Pen(clr),pt);
  }
  
 }
}


 

 

 

原创粉丝点击