CameraBookDayControl.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.ComponentLibrary
  10. {
  11. public partial class CameraBookDayControl : Panel
  12. {
  13. public Model.CameraBook.DayDataModel dayModel;
  14. public delegate void ClickRemarkHandler(CameraBookDayControl pan, string day);
  15. public ClickRemarkHandler ClickRemarkEvent;
  16. public delegate void DoubleClickItemHandler(CameraBookDayControl pan, string dayNum, Model.CameraBook.DayDataItemModel dayDataItem);
  17. public DoubleClickItemHandler DoubleClickItemEvent;
  18. string nowTipsText = "";
  19. public CameraBookDayControl()
  20. {
  21. InitializeComponent();
  22. SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
  23. toolTip1.AutoPopDelay = 5000;
  24. toolTip1.InitialDelay = 1000;
  25. toolTip1.ReshowDelay = 500;
  26. }
  27. /// <summary>
  28. /// 设置提示内容
  29. /// </summary>
  30. /// <param name="tipText"></param>
  31. void SetTipsText(string tipText)
  32. {
  33. if (dayModel != null)
  34. {
  35. if (nowTipsText != tipText)
  36. {
  37. toolTip1.SetToolTip(this, tipText);
  38. nowTipsText = tipText;
  39. }
  40. }
  41. }
  42. /// <summary>
  43. /// 初始值赋值
  44. /// </summary>
  45. /// <param name="_dayModel"></param>
  46. public void SetDayDataModel(Model.CameraBook.DayDataModel _dayModel)
  47. {
  48. dayModel = _dayModel;
  49. if (dayModel != null)
  50. {
  51. SetTipsText(dayModel.TipText);
  52. }
  53. else
  54. {
  55. toolTip1.SetToolTip(this, "");
  56. }
  57. this.Refresh();
  58. }
  59. /// <summary>
  60. /// 自定义单击事件
  61. /// </summary>
  62. /// <param name="e"></param>
  63. protected override void OnMouseClick(MouseEventArgs e)
  64. {
  65. if (dayModel != null)
  66. {
  67. if (MouthOnDayModel(e.Location))
  68. {
  69. if(ClickRemarkEvent!=null)
  70. {
  71. ClickRemarkEvent(this,dayModel.dayNum);
  72. }
  73. }
  74. }
  75. base.OnMouseClick(e);
  76. }
  77. /// <summary>
  78. /// 自定义双击事件
  79. /// </summary>
  80. /// <param name="e"></param>
  81. protected override void OnMouseDoubleClick(MouseEventArgs e)
  82. {if (dayModel != null)
  83. {
  84. Model.CameraBook.DayDataItemModel itemModel = new Model.CameraBook.DayDataItemModel();
  85. if (MouthOnDayItemModel(e.Location,ref itemModel))
  86. {
  87. if(DoubleClickItemEvent!=null)
  88. {
  89. DoubleClickItemEvent(this,dayModel.dayNum,itemModel);
  90. }
  91. }
  92. }
  93. base.OnMouseDoubleClick(e);
  94. }
  95. /// <summary>
  96. /// 鼠标移动事件
  97. /// </summary>
  98. /// <param name="e"></param>
  99. protected override void OnMouseMove(MouseEventArgs e)
  100. {
  101. if (dayModel != null)
  102. {
  103. if (MouthOnDayModel(e.Location))
  104. {
  105. Cursor.Current = Cursors.Hand;
  106. SetTipsText( "每日便签");
  107. }
  108. else
  109. {
  110. Model.CameraBook.DayDataItemModel itemModel = new Model.CameraBook.DayDataItemModel();
  111. if (MouthOnDayItemModel(e.Location,ref itemModel))
  112. {
  113. Cursor.Current = Cursors.Hand;
  114. SetTipsText( itemModel.TipText);
  115. }
  116. else
  117. {
  118. Cursor.Current = Cursors.Default;
  119. SetTipsText(dayModel.TipText);
  120. }
  121. }
  122. }
  123. base.OnMouseMove(e);
  124. }
  125. /// <summary>
  126. /// 鼠标是否处于月份日期
  127. /// </summary>
  128. /// <param name="location"></param>
  129. /// <returns></returns>
  130. bool MouthOnDayModel(Point location)
  131. {
  132. return location.X >= dayModel.StrPostion.X && location.X <= dayModel.StrPostion.X + dayModel.StrSize.Width &&
  133. location.Y >= dayModel.StrPostion.Y && location.Y <= dayModel.StrPostion.Y + dayModel.StrSize.Height;
  134. }
  135. /// <summary>
  136. /// 鼠标是否处于内容中
  137. /// </summary>
  138. /// <param name="location"></param>
  139. /// <param name="retItemModel"></param>
  140. /// <returns></returns>
  141. bool MouthOnDayItemModel(Point location,ref Model.CameraBook.DayDataItemModel retItemModel)
  142. {
  143. Model.CameraBook.DayDataItemModel itemModel = dayModel.list.Find(p => location.X >= p.StrPostion.X && location.X <= p.StrPostion.X + p.StrSize.Width &&
  144. location.Y >= p.StrPostion.Y && location.Y <= p.StrPostion.Y + p.StrSize.Height);
  145. if (itemModel != null)
  146. {
  147. retItemModel = itemModel;
  148. return true;
  149. }
  150. else
  151. {
  152. return false;
  153. }
  154. }
  155. /// <summary>
  156. /// 绘制实体内容
  157. /// </summary>
  158. /// <param name="pe"></param>
  159. protected override void OnPaint(PaintEventArgs pe)
  160. {
  161. if (dayModel != null)
  162. {
  163. Graphics g = pe.Graphics;
  164. if (string.IsNullOrEmpty(dayModel.remark.Trim()))
  165. {
  166. g.DrawString(dayModel.dayNum, new Font("微软雅黑", 15), new SolidBrush(Color.Red), new PointF(10, 10));
  167. }
  168. else
  169. {
  170. g.DrawString(dayModel.dayNum, new Font("微软雅黑", 15), new SolidBrush(Color.Blue), new PointF(10, 10));
  171. }
  172. dayModel.StrPostion = new PointF(10, 10);
  173. dayModel.StrSize = g.MeasureString(dayModel.dayNum, new Font("微软雅黑", 15));
  174. g.DrawString(dayModel.strLunar, new Font("微软雅黑", 12), new SolidBrush(Color.Black), new PointF(50, 15));
  175. float height = 22;
  176. for (int i = 0; i < dayModel.list.Count; i++)
  177. {
  178. //height = height + i * height;
  179. g.DrawString(dayModel.list[i].Name + dayModel.list[i].Number, new Font("微软雅黑", 10), new SolidBrush(Color.Black), new PointF(10, height + 20 * (i + 1)));
  180. dayModel.list[i].StrPostion = new PointF(10, height + 20 * (i + 1));
  181. dayModel.list[i].StrSize = g.MeasureString(dayModel.list[i].Name + dayModel.list[i].Number, new Font("微软雅黑", 10));
  182. }
  183. }
  184. }
  185. }
  186. }