日历画图

 

记得先引用画图类

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值