日历画图

 

记得先引用画图类

using System.Drawing;

偏移量根据自己的程序动态设定。offset的范围为0-6

 

     void  Test()
    
{
        
int x_max = 220;
        
int y_max = 150;

        System.Drawing.Image myImage 
= new System.Drawing.Bitmap(x_max, y_max);
        System.Drawing.Graphics g 
= System.Drawing.Graphics.FromImage(myImage);
        g.Clear(Color.White);
        Pen newPen 
= new Pen(Color.Red, 1);

        Font font 
= new Font("宋体"10);

        Font font2 
= new Font("宋体"9);
        SolidBrush brush 
= new SolidBrush(Color.Blue);
        SolidBrush brush2 
= new SolidBrush(Color.Black);



        
//竖线
        for (int ii = 0; ii <= 7; ii++)
        
{
            Point a 
= new Point(ii * 300);
            Point b 
= new Point(ii * 3020 * 7);

            g.DrawLine(newPen, a, b);
        }

        
//横线
        for (int ii = 0; ii <= 7; ii++)
        
{
            Point a 
= new Point(0, ii * 20);
            Point b 
= new Point(30 * 7, ii * 20);

            g.DrawLine(newPen, a, b);
        }




        
string[] strHead ="""""""""""""" };

        
string[] strItem ="初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",
                            
"十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
                            
"廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"}
;



        
//偏移量(0-6),可以尝试修改看看效果
        int offset = 0;

        
if (offset >= 0 && offset <= 6)
        
{
            
for (int jj = 0; jj <= 5; jj++)
            
{
                
for (int ii = 0; ii <= 6; ii++)
                
{
                    
switch (jj)
                    
{
                        
case 0:
                            g.DrawString(strHead[ii], font, brush, 
30 * ii + 1020 * jj + 5);
                            
break;
                        
default:
                            
if ((ii + (jj - 1* 7< strItem.Length)
                            
{
                                
int x = 30 * (ii + offset) + 1;
                                
int y = 20 * jj + 5;

                                
if (x + 20 < x_max)
                                    g.DrawString(strItem[ii 
+ (jj - 1* 7], font2, brush2, x, y);
                                
else
                                    g.DrawString(strItem[ii 
+ (jj - 1* 7], font2, brush2, x - 210, y + 20);


                            }

                            
break;
                    }

                }

            }

            myImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        }

    }

 当偏移量为0、1、5、6的效果图为:

日历画图_第1张图片

你可能感兴趣的:(日历,string)