123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.ComponentLibrary
- {
- public partial class CameraBookDayControl : Panel
- {
- public Model.CameraBook.DayDataModel dayModel;
- public delegate void ClickRemarkHandler(CameraBookDayControl pan, string day);
- public ClickRemarkHandler ClickRemarkEvent;
- public delegate void DoubleClickItemHandler(CameraBookDayControl pan, string dayNum, Model.CameraBook.DayDataItemModel dayDataItem);
- public DoubleClickItemHandler DoubleClickItemEvent;
- string nowTipsText = "";
- public CameraBookDayControl()
- {
- InitializeComponent();
- SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
- toolTip1.AutoPopDelay = 5000;
- toolTip1.InitialDelay = 1000;
- toolTip1.ReshowDelay = 500;
-
- }
-
- /// <summary>
- /// 设置提示内容
- /// </summary>
- /// <param name="tipText"></param>
- void SetTipsText(string tipText)
- {
- if (dayModel != null)
- {
- if (nowTipsText != tipText)
- {
- toolTip1.SetToolTip(this, tipText);
- nowTipsText = tipText;
- }
- }
- }
- /// <summary>
- /// 初始值赋值
- /// </summary>
- /// <param name="_dayModel"></param>
- public void SetDayDataModel(Model.CameraBook.DayDataModel _dayModel)
- {
- dayModel = _dayModel;
- if (dayModel != null)
- {
- SetTipsText(dayModel.TipText);
- }
- else
- {
- toolTip1.SetToolTip(this, "");
- }
- this.Refresh();
- }
- /// <summary>
- /// 自定义单击事件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnMouseClick(MouseEventArgs e)
- {
- if (dayModel != null)
- {
- if (MouthOnDayModel(e.Location))
- {
- if(ClickRemarkEvent!=null)
- {
- ClickRemarkEvent(this,dayModel.dayNum);
- }
- }
-
- }
- base.OnMouseClick(e);
- }
- /// <summary>
- /// 自定义双击事件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnMouseDoubleClick(MouseEventArgs e)
- {if (dayModel != null)
- {
- Model.CameraBook.DayDataItemModel itemModel = new Model.CameraBook.DayDataItemModel();
- if (MouthOnDayItemModel(e.Location,ref itemModel))
- {
- if(DoubleClickItemEvent!=null)
- {
- DoubleClickItemEvent(this,dayModel.dayNum,itemModel);
- }
- }
- }
- base.OnMouseDoubleClick(e);
- }
-
- /// <summary>
- /// 鼠标移动事件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (dayModel != null)
- {
- if (MouthOnDayModel(e.Location))
- {
- Cursor.Current = Cursors.Hand;
- SetTipsText( "每日便签");
- }
- else
- {
- Model.CameraBook.DayDataItemModel itemModel = new Model.CameraBook.DayDataItemModel();
- if (MouthOnDayItemModel(e.Location,ref itemModel))
- {
- Cursor.Current = Cursors.Hand;
- SetTipsText( itemModel.TipText);
- }
- else
- {
- Cursor.Current = Cursors.Default;
- SetTipsText(dayModel.TipText);
- }
- }
- }
- base.OnMouseMove(e);
- }
- /// <summary>
- /// 鼠标是否处于月份日期
- /// </summary>
- /// <param name="location"></param>
- /// <returns></returns>
- bool MouthOnDayModel(Point location)
- {
- return location.X >= dayModel.StrPostion.X && location.X <= dayModel.StrPostion.X + dayModel.StrSize.Width &&
- location.Y >= dayModel.StrPostion.Y && location.Y <= dayModel.StrPostion.Y + dayModel.StrSize.Height;
- }
- /// <summary>
- /// 鼠标是否处于内容中
- /// </summary>
- /// <param name="location"></param>
- /// <param name="retItemModel"></param>
- /// <returns></returns>
- bool MouthOnDayItemModel(Point location,ref Model.CameraBook.DayDataItemModel retItemModel)
- {
- Model.CameraBook.DayDataItemModel itemModel = dayModel.list.Find(p => location.X >= p.StrPostion.X && location.X <= p.StrPostion.X + p.StrSize.Width &&
- location.Y >= p.StrPostion.Y && location.Y <= p.StrPostion.Y + p.StrSize.Height);
- if (itemModel != null)
- {
- retItemModel = itemModel;
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 绘制实体内容
- /// </summary>
- /// <param name="pe"></param>
- protected override void OnPaint(PaintEventArgs pe)
- {
- if (dayModel != null)
- {
- Graphics g = pe.Graphics;
- if (string.IsNullOrEmpty(dayModel.remark.Trim()))
- {
- g.DrawString(dayModel.dayNum, new Font("微软雅黑", 15), new SolidBrush(Color.Red), new PointF(10, 10));
- }
- else
- {
- g.DrawString(dayModel.dayNum, new Font("微软雅黑", 15), new SolidBrush(Color.Blue), new PointF(10, 10));
- }
- dayModel.StrPostion = new PointF(10, 10);
- dayModel.StrSize = g.MeasureString(dayModel.dayNum, new Font("微软雅黑", 15));
- g.DrawString(dayModel.strLunar, new Font("微软雅黑", 12), new SolidBrush(Color.Black), new PointF(50, 15));
- float height = 22;
- for (int i = 0; i < dayModel.list.Count; i++)
- {
- //height = height + i * height;
- g.DrawString(dayModel.list[i].Name + dayModel.list[i].Number, new Font("微软雅黑", 10), new SolidBrush(Color.Black), new PointF(10, height + 20 * (i + 1)));
- dayModel.list[i].StrPostion = new PointF(10, height + 20 * (i + 1));
- dayModel.list[i].StrSize = g.MeasureString(dayModel.list[i].Name + dayModel.list[i].Number, new Font("微软雅黑", 10));
- }
- }
- }
- }
- }
|