ITPub博客

首页 > Linux操作系统 > Linux操作系统 > GDI+带农历的万年历(周历)之制作

GDI+带农历的万年历(周历)之制作

原创 Linux操作系统 作者:大可山 时间:2009-01-06 10:34:14 0 删除 编辑

今天在网上无意中搜索到“Vista风格日历控件”(http://www.cnpopsoft.com/article.asp?id=56)。下载之后发现,略有BUG,于是进行改进。无意中,制作出来带农历的万年历(周历版)。

运行如下图:


主要的改进在:
// frmDemo.cs
//#####################################################################################
//★★★★★★★           http://www.cnpopsoft.com [华普软件]           ★★★★★★★
//★★ '华普软件-VB、C#专业论文与源码荟萃,敏捷开发,平台战略,让商业软件靓起来!  ★★
//#####################################################################################

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CNPOPSOFT.Controls
{
    public partial class frmDemo : Form
    {
        public frmDemo()
        {
            //InitializeComponent();
            this.Load += new System.EventHandler(this.frmDemo_Load);
        }

        private void frmDemo_Load(object sender, EventArgs e)
        {
            InitContent();
        }

         ///


        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        ///

        private void InitContent()
        {
            this.SuspendLayout();

            int calendarX = 0;
            int calendarY = 0;
            int ffsetX = -10;
            int ffsetY = -10;
            int columns = 7;
            int rows = 1;

            VistaCalendar[] vistaCalendarList = new VistaCalendar[columns * rows];
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.White;
            this.ClientSize = new System.Drawing.Size(1024, 700);

            DateTime dateTimeNow = DateTime.Now;
            int year = dateTimeNow.Year;
            int month = dateTimeNow.Month;
            int day = dateTimeNow.Day;

            int styleCount = Enum.GetNames(typeof(CNPOPSOFT.Controls.VistaCalendar.VistaCalendarStyle)).Length;

            for (int i = 0; i < vistaCalendarList.Length; i++)
            {
                vistaCalendarList[i] = new VistaCalendar();
                vistaCalendarList[i].BackColor = System.Drawing.Color.Transparent;
                vistaCalendarList[i].CurrentDate = dateTimeNow.AddDays(i);
                vistaCalendarList[i].IsUseToday = false;
                calendarX = (i % columns) * (155 + offsetX);
                calendarY = (i / columns) * (160 + offsetY);
                vistaCalendarList[i].Location = new System.Drawing.Point(calendarX, calendarY);
                vistaCalendarList[i].Name = "vistaCalendar" + (i+1).ToString();
                vistaCalendarList[i].Size = new System.Drawing.Size(155, 160);

                vistaCalendarList[i].Style. = (CNPOPSOFT.Controls.VistaCalendar.VistaCalendarStyle)((i + i/columns) % styleCount);

                vistaCalendarList[i].TabIndex = i + 1;

                this.Controls.Add(vistaCalendarList[i]);
            }

            //
            // frmDemo
            //
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmDemo";
            this.Text = "Vista时钟控件";
            this.Load += new System.EventHandler(this.frmDemo_Load);
            this.ResumeLayout(false);

        }

    }
}

VistaCalendar.cs中新增了CurrentDate和IsUseToday两个公共属性:
        public DateTime CurrentDate
        {
            get
            {
                return _currentDate;
            }
            set
            {
                _currentDate = value;
            }
        }

        public bool IsUseToday
        {
            get { return _isUseToday; }
            set { _isUseToday = value; }
        }

并将UpdateCurrentDateInfo();由构造函数中放到了void VistaCalendar_Paint(object sender, PaintEventArgs e)中,这样更加合理。其他地方的微小改动包括字体大小等。

在此,谨向原作者致谢!感谢他的辛勤劳动!


 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14601556/viewspace-528507/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
IT人士,爱好编程的码农。

注册时间:2008-06-19

  • 博文量
    118
  • 访问量
    692460