修改的Vista风格多功能日历Demo

Vista风格日历程序来源于网上开源程序,首先感谢下原作者的无私奉献!

在原来基础上稍作修改添加了一些演示,效果如图:

 

修改的Vista风格多功能日历Demo 

 

新增演示:1,gdi绘制小图标,

              2,带图标的ComboBox 

 

实际应用:

           可以抓取气象网上的气象信息,做一个完善的小程序。


代码:

带图标的ComboBox
public   class  UIcombox : ComboBox
    {
        
public  UIcombox()
        {
            DrawMode 
=  DrawMode.OwnerDrawFixed;
        }
        
private  ImageList _ListaImg  =   new  ImageList();

        
public  ImageList ImageList
        {
            
get
            {
                
return  _ListaImg;
            }
            
set
            {
                _ListaImg 
=  value;
            }
        }

        
private   bool  _ShowTitle  =   true ;
        
public   bool  ShowTitle
        {
            
get
            {
                
return  _ShowTitle;
            }
            
set
            {
                _ShowTitle 
=  value;
            }
        }
        
protected   override   void  OnDrawItem(DrawItemEventArgs e)
        {
            
if  (e.Index  >=   0 )
            {
                e.DrawBackground();
                e.DrawFocusRectangle();
                Rectangle bounds 
=   new  Rectangle();

                bounds 
=  e.Bounds;

                
string  s  =   "" ;
                
if  (_ShowTitle  ==   true )
                {
                    s 
=   this .Items[e.Index].ToString();
                }

                
try
                {
                    
if  (_ListaImg.Images.Count  !=   0 )
                    {
                        
// _ListaImg.ImageSize = new Size(this.Height - 8, this.Height - 8);  /*此处new操作之后_ListImg会为NULL*/
                        _ListaImg.Draw(e.Graphics, bounds.Left, bounds.Top, e.Index);
                        e.Graphics.DrawString(s, e.Font, 
new  SolidBrush(e.ForeColor), bounds.Left  +  _ListaImg.Images[e.Index].Width, bounds.Top);
                    }
                    
else
                    {
                        e.Graphics.DrawString(s, e.Font, 
new  SolidBrush(e.ForeColor), bounds.Left, bounds.Top);
                    }
                }
                
catch     /* ImageList中Images尽量与ComBox中Items对应 */
                {
                    e.Graphics.DrawString(s, e.Font, 
new  SolidBrush(e.ForeColor), bounds.Left, bounds.Top);
                }
            }
            
base .OnDrawItem(e);
        }
    }

 

 

完整项目下载: /Files/cxwx/VistaCalendarProject.rar

 

你可能感兴趣的:(demo)