页面和变换(一)

画标尺:

()手工转换

 

using System;

using   System.Drawing ;

using System.Drawing.Printing ;

using  System.Windows.Forms ;

namespace WindowsProgram

{

     class TenCenTimeterRuler:PrintTableForm

     {

         static void Main(string[] args)

         {

              Application.Run(new TenCenTimeterRuler());

         }

         public  TenCenTimeterRuler()

         {

              Text="Ten Cen Timeter Ruler";

             

         }

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

         {

                   Pen pen=new Pen(clr);

              Brush brush=new SolidBrush(clr);

              const  int xOffset=10;

              const  int yOffset=10;

              grs.DrawPolygon(pen,new PointF[]{MMConv(grs,new PointF(xOffset,yOffset)),

                                  MMConv(grs,new PointF(xOffset+150,yOffset)),

                                  MMConv(grs,new PointF(xOffset+150,yOffset+10)),

                                    MMConv(grs,new PointF(xOffset,yOffset+10))});

              StringFormat stmmt=new StringFormat();

              stmmt.Alignment =StringAlignment.Center;          

              for ( int i=0;i<150;i++)

            {

                   if(i%10==0)

                   {

                            grs.DrawLine(pen,MMConv(grs,new PointF(xOffset+i,yOffset)),

                        MMConv(grs,new PointF(xOffset+i,yOffset+5)));

                       grs.DrawString((i/10).ToString(),Font,brush,

                            MMConv(grs,new PointF(xOffset+i,yOffset+5)),stmmt);

                   }

                   else

                   {   

                       if(i%5==0)

                       {

                            grs.DrawLine(pen,MMConv(grs,new PointF(xOffset+i,yOffset)),

                                 MMConv(grs,new PointF(xOffset+i,yOffset+3)));

                       }

                       else

                       {

                            grs.DrawLine(pen,MMConv(grs,new PointF(xOffset+i,yOffset)),

                                 MMConv(grs,new PointF(xOffset+i,yOffset+2.5f)));

                       }

                   }

            

              }

             

             

                   //grs.DrawEllipse(new Pen(clr),0,0,grs.DpiX,grs.DpiY);

         }

         PointF MMConv(Graphics grs,PointF pointf)// 象素转换成毫米

        {

         pointf.X *=grs.DpiX /25.4f;//因为1英寸 =25.4毫米,1cm=0.394 英寸

         pointf.Y *=grs.DpiY /25.4f;

         return pointf ;

        }

        

     }

}

()自动转换

 

using System;

using   System.Drawing ;

using System.Drawing.Printing ;

using  System.Windows.Forms ;

namespace WindowsProgram

{

     class TenCenTimeterRulerAuTo:PrintTableForm

     {

         static void Main(string[] args)

         {

              Application.Run(new TenCenTimeterRulerAuTo());

         }

         public  TenCenTimeterRulerAuTo()

         {

              Text="Ten Cen Timeter Ruler";

             

         }

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

         {

             

              Pen pen=new Pen(clr,0.25f);

              Brush brush=new SolidBrush(clr);

              const  int xOffset=10;

              const  int yOffset=10;

              grs.PageUnit=GraphicsUnit.Millimeter;

              grs.PageScale=1;

 

              grs.DrawRectangle(pen,xOffset,yOffset,150,10);

              StringFormat stmmt=new StringFormat();

              stmmt.Alignment =StringAlignment.Center;          

              for ( int i=0;i<150;i++)

            {     if(i%10==0)

                   {    grs.DrawLine(pen,new PointF(xOffset+i,yOffset),

                        new PointF(xOffset+i,yOffset+5));

                        grs.DrawString((i/10).ToString(),Font,brush,

                            new PointF(xOffset+i,yOffset+5),stmmt);

                   }

                   else

                   {   

                       if(i%5==0)

                       {    grs.DrawLine(pen,new PointF(xOffset+i,yOffset),

                                 new PointF(xOffset+i,yOffset+3));

                       }

                        else

                       {grs.DrawLine(pen,new PointF(xOffset+i,yOffset),

                                 new PointF(xOffset+i,yOffset+2.5f));

                       }

                   }           

              }       

         }       

     }

}

7.7画笔宽度

 

using System;

using   System.Drawing ;

using System.Drawing.Printing ;

using  System.Windows.Forms ;

namespace WindowsProgram

{

     class PenWidths:PrintTableForm

     {

         static void Main(string[] args)

         {

              Application.Run(new PenWidths());

         }

         public  PenWidths()

         { Text="Pen Widths";            

         }

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

         {    Brush brush=new SolidBrush(clr);

              float y=0;

              grs.PageUnit=GraphicsUnit.Millimeter;

              grs.PageScale=1;           

              StringFormat stmmt=new StringFormat();

              stmmt.Alignment =StringAlignment.Center;          

              for ( float f=0;f<3.2;f+=0.2f)

            { Pen pen=new Pen(clr,f);

             string  str=String.Format("{0:F1} Point wide Pen:",f);

               SizeF  sizef=grs.MeasureString(str,Font);

               grs.DrawString(str,Font,brush,0,y);

               grs.DrawLine(pen,sizef.Width,y+sizef.Height/2,sizef.Width+144,y+sizef.Height/2);

               y+=Font.Height/2;        

              }            

         }       

     }

}

阅读更多
个人分类: C#基础
想对作者说点什么? 我来说一句

变换背景色的页面.rar

2010年03月23日 2KB 下载

HHT变换程序(完整的一套)

2012年06月04日 53KB 下载

Scattering flowers动态散花背景

2015年09月08日 8KB 下载

javascript 颜色选择器

2010年04月21日 1KB 下载

没有更多推荐了,返回首页

不良信息举报

页面和变换(一)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭