修改的Vista风格多功能日历Demo
Vista风格日历程序来源于网上开源程序,首先感谢下原作者的无私奉献!
在原来基础上稍作修改添加了一些演示,效果如图:
新增演示:1,gdi绘制小图标,
2,带图标的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);
}
}
{
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架