欢迎来到飞鸟慕鱼博客,开始您的技术之旅!
当前位置: 首页知识笔记正文

用尼奥斯夫写的闪光日历(非正式版)

终极管理员 知识笔记 61阅读

使用系统;使用系统。绘图;使用系统。收藏;使用系统窗户100 .FormsnamespaceFlashvan .控件{ public class calendar : control { protected visual header=null;受保护的视觉[]单元格=0,0,255,1)' null;protectedTextElement[]title=null;protectedTextElement[]label=null;protectedintweekFirstDay=0;protectedDateTimeinitdate=null;protecteddintdaysofmount=31 protecteddintcellspacing

: rgba(0, 0, 0, 1)">= 2;        //日历各个格子的间隔
        protected int cellWidth = 0;        //日历各个格子的高度
        protected int cellHeight = 0;        //日历各个格子的宽度
        
        
//        private int firstDay; //
//        this._firstDay        = this._initDate.getDay();
//        this._firstCell        = (this._firstDay + this._weekFirstDay) % 7;
//        this._daysOfMonth    = 32 - (new Date(this._year, this._month-1, 32)).getDate();
        
        
//==============================================================================================================================
         
        
// 星期日到星期六的名称
        private string[] weekNames = {"Sun""Mon""Tue""Wed""Thu""Fri""Sat"};
        
public string[] WeekNames
        
{
            
get {return this.weekNames; }
            
            
set {this.weekNames = value; }
        }

        
        
// 当前显示的年
        private int year;
        
public int Year
        
{
            
get {return this.year; }
            
set {this.year  = value; }
        }

        
        
// 当前显示的月
        private int month;
        
public int Month
        
{
            
get {return this.month; }
            
set {this.month  = value; }
        }

        
        
//日历头的高度
        private int headerHeight = 30;        
        
public int HeaderHeight
        
{
            
get return this.headerHeight; }
            
set this.headerHeight = value; }
        }

        
        
//被选日期组成的列表
        private ArrayList selecteddates;
        
public ArrayList SelectedDates
        
{
            
get return this.selecteddates; }
            
set this.selecteddates = value; }
        }

       
        
public DateTime InitDate
        
{
            
get {return this.initdate; }
            
set 
            
{
                
this.initdate = new DateTime(value.Year,value.Month, 1);
            }

        }

        

        
//==============================================================================================================================
       
        
public Calendar()
        
{
            
//
            
// TODO: Add constructor logic here
            
//
            this.Size = new Size(200,150);
            
this.BackColor = Color.LightGray;
            
this.TabStop = true;
            
this.initdate = new DateTime(DateTime.Today.Year,DateTime.Today.Month,1);
            
            
this.selecteddates = new ArrayList();
            
            selecteddates.Add(DateTime.Today);
            
            
            
            DateTime dt 
= new DateTime(initdate.Year, initdate.Month+1,1);
            
            
this.daysOfMonth = dt.DayOfYear - initdate.DayOfYear;
            
            
        }

        

        
        
// 建立控件
        protected override void OnCreateControl()
        
{
            
//header visual
            this.header = new Visual(this.Visual);
            
            
this.title = new TextElement[7];
            
            
for(int i = 0; i < title.Length; i++ ) 
            
{
                title[i] 
= new TextElement(this.header);
            }

            
            
//cell visual 
            this.cell = new Visual[7 * 6];
            
            
this.label = new TextElement[7 * 6];
            
            
for(int i = 0; i < cell.Length; i++ ) 
            
{
                    cell[i] 
= new Visual(this.Visual);
                    label[i] 
= new TextElement(cell[i]);
            }

            
        }

        
        
// OnPaint
        protected override void OnPaint(PaintEventArgs pe)
        
{
            OnPaintHeader(pe);
            OnPaintTitle(pe);
            OnPaintCell(pe);
            OnPaintLabel(pe);
            OnPaintSelectedCell(pe);

        }

        
        
// 画出日历的头
        private void OnPaintHeader(PaintEventArgs pe)
        
{
            
this.header.Clear();
            
this.header.BeginSolidFill(Color.Silver);
            
this.header.DrawRectangle(0,0,this.Width,this.headerHeight);
        }

        
        
// 画出日历的头文字
        private void OnPaintTitle(PaintEventArgs pe)
        
{
            Font font
= new Font("Arial",10, FontStyle.Bold, GraphicsUnit.Pixel );
//            for(int i = 0; i < FontFamily.Families.Length; i++)
//                System.Diagnostics.Trace.WriteLine(FontFamily.Families[0].Name);
            for(int i = 0; i < title.Length; i++)
            
{
                title[i].X 
= this.cellSpacing * ( i + 1+ this.cellWidth * i;
                title[i].Y 
= 0;
                
this.title[i].Font = font;
                title[i].Width 
= this.cellWidth;
                title[i].Height 
= this.cellHeight;
                title[i].Alignment 
= ContentAlignment.MiddleCenter;
                title[i].Text 
= this.weekNames[i];
            }

        }

        
        
// 画出所有的日期格子
        private void OnPaintCell(PaintEventArgs pe)
        
{

            
for(int i = 0; i < 7; i++)
            
{
                
for(int j = 0; j< 6; j++)
                
{
                    Visual c 
= cell[i + j * 7];
                    c.Clear();
                    c.X 
= this.cellSpacing * (i + 1+ this.cellWidth * i;
                    c.Y 
= this.cellSpacing * (j + 1+ this.cellHeight * j + this.headerHeight;
                    c.BeginSolidFill(Color.WhiteSmoke);
                    c.DrawRectangle(
00this.cellWidth, this.cellHeight);
                    c.EndFill();        
                }

            }

        }

        
        
// 画出日期文字
        private void OnPaintLabel(PaintEventArgs pe)
        
{
            
for(int i = 0; i < (intthis.initdate.DayOfWeek; i++)
            
{
                
this.label[i].Text = "";
                
this.label[i].Visible = false;
            }

            
            
for(int i = 0; i < this.daysOfMonth; i++)
            

                TextElement t 
= this.label[i + (intthis.initdate.DayOfWeek];
                
//t.Alignment = ContentAlignment.MiddleCenter;
                t.Text = (i + 1).ToString();
                t.Visible 
= true;
                
            }

            
            
for(int i = (intthis.initdate.DayOfWeek + this.daysOfMonth;  i < 42; i++)
            
{
                
this.label[i].Text = "";
                
this.label[i].Visible = false;
            }

            
            
//this.TextChanged(this,EventArgs.Empty);
        }

        
        
// 绘制选择了的日期格子
        private void OnPaintSelectedCell(PaintEventArgs pe)
        
{

            
for(int i = 0; i< this.selecteddates.Count; i++)
            
{
                DateTime dt 
= (DateTime) this.selecteddates[i];
                Visual c 
= cell[(intthis.initdate.DayOfWeek + dt.Day - 1];
                c.Clear();
                c.BeginSolidFill(Color.LightSlateGray);
                c.DrawRectangle(
00this.cellWidth, this.cellHeight);
                c.EndFill();
            }

            
        }

        
        
// 重载, 当日历大小变化时
        protected override void OnSizeChanged( EventArgs e )
        
{
            
            
this.cellWidth = (this.Width - this.cellSpacing * 8/ 7;
            
this.cellHeight = (this.Height - this.cellSpacing * 7 - this.headerHeight) / 6;
            
this.Invalidate();
        }

        
        

    }

}

生成flash:

标签:
声明:无特别说明,转载请标明本文来源!