UIControl.6.Events.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. using System;
  2. using System.Windows.Forms;
  3. namespace Microsoft.Windows.Forms
  4. {
  5. partial class UIControl
  6. {
  7. private static readonly object EVENT_PARENT_CHANGED = new object();
  8. /// <summary>
  9. /// 父控件改变事件
  10. /// </summary>
  11. public event EventHandler ParentChanged
  12. {
  13. add
  14. {
  15. base.Events.AddHandler(EVENT_PARENT_CHANGED, value);
  16. }
  17. remove
  18. {
  19. base.Events.RemoveHandler(EVENT_PARENT_CHANGED, value);
  20. }
  21. }
  22. /// <summary>
  23. /// 触发父控件改变事件
  24. /// </summary>
  25. /// <param name="e">数据</param>
  26. protected virtual void OnParentChanged(EventArgs e)
  27. {
  28. EventHandler handler = base.Events[EVENT_PARENT_CHANGED] as EventHandler;
  29. if (handler != null)
  30. handler(this, e);
  31. }
  32. private static readonly object EVENT_ENTER = new object();
  33. /// <summary>
  34. /// 鼠标进入事件
  35. /// </summary>
  36. public event EventHandler Enter
  37. {
  38. add
  39. {
  40. base.Events.AddHandler(EVENT_ENTER, value);
  41. }
  42. remove
  43. {
  44. base.Events.RemoveHandler(EVENT_ENTER, value);
  45. }
  46. }
  47. /// <summary>
  48. /// 触发鼠标进入事件
  49. /// </summary>
  50. /// <param name="e"></param>
  51. protected virtual void OnEnter(EventArgs e)
  52. {
  53. EventHandler handler = base.Events[EVENT_ENTER] as EventHandler;
  54. if (handler != null)
  55. handler(this, e);
  56. }
  57. private static readonly object EVENT_LEAVE = new object();
  58. /// <summary>
  59. /// 鼠标离开事件
  60. /// </summary>
  61. public event EventHandler Leave
  62. {
  63. add
  64. {
  65. base.Events.AddHandler(EVENT_LEAVE, value);
  66. }
  67. remove
  68. {
  69. base.Events.RemoveHandler(EVENT_LEAVE, value);
  70. }
  71. }
  72. /// <summary>
  73. /// 触发鼠标离开事件
  74. /// </summary>
  75. /// <param name="e">数据</param>
  76. protected virtual void OnLeave(EventArgs e)
  77. {
  78. EventHandler handler = base.Events[EVENT_LEAVE] as EventHandler;
  79. if (handler != null)
  80. handler(this, e);
  81. }
  82. private static readonly object EVENT_LOCATION_CHANGED = new object();
  83. /// <summary>
  84. /// 坐标改变事件
  85. /// </summary>
  86. public event EventHandler LocationChanged
  87. {
  88. add
  89. {
  90. base.Events.AddHandler(EVENT_LOCATION_CHANGED, value);
  91. }
  92. remove
  93. {
  94. base.Events.RemoveHandler(EVENT_LOCATION_CHANGED, value);
  95. }
  96. }
  97. /// <summary>
  98. /// 触发坐标改变事件
  99. /// </summary>
  100. /// <param name="e">数据</param>
  101. protected virtual void OnLocationChanged(EventArgs e)
  102. {
  103. EventHandler handler = base.Events[EVENT_LOCATION_CHANGED] as EventHandler;
  104. if (handler != null)
  105. handler(this, e);
  106. }
  107. private static readonly object EVENT_SIZE_CHANGED = new object();
  108. /// <summary>
  109. /// 大小改变事件
  110. /// </summary>
  111. public event EventHandler SizeChanged
  112. {
  113. add
  114. {
  115. base.Events.AddHandler(EVENT_SIZE_CHANGED, value);
  116. }
  117. remove
  118. {
  119. base.Events.RemoveHandler(EVENT_SIZE_CHANGED, value);
  120. }
  121. }
  122. /// <summary>
  123. /// 触发大小改变事件
  124. /// </summary>
  125. /// <param name="e">数据</param>
  126. protected virtual void OnSizeChanged(EventArgs e)
  127. {
  128. EventHandler handler = base.Events[EVENT_SIZE_CHANGED] as EventHandler;
  129. if (handler != null)
  130. handler(this, e);
  131. }
  132. private static readonly object EVENT_MOUSE_DOWN = new object();
  133. /// <summary>
  134. /// 鼠标按下事件
  135. /// </summary>
  136. public event MouseEventHandler MouseDown
  137. {
  138. add
  139. {
  140. base.Events.AddHandler(EVENT_MOUSE_DOWN, value);
  141. }
  142. remove
  143. {
  144. base.Events.RemoveHandler(EVENT_MOUSE_DOWN, value);
  145. }
  146. }
  147. /// <summary>
  148. /// 触发鼠标按下事件
  149. /// </summary>
  150. /// <param name="e">数据</param>
  151. protected virtual void OnMouseDown(MouseEventArgs e)
  152. {
  153. MouseEventHandler handler = base.Events[EVENT_MOUSE_DOWN] as MouseEventHandler;
  154. if (handler != null)
  155. handler(this, e);
  156. }
  157. private static readonly object EVENT_MOUSE_UP = new object();
  158. /// <summary>
  159. /// 鼠标弹起事件
  160. /// </summary>
  161. public event MouseEventHandler MouseUp
  162. {
  163. add
  164. {
  165. base.Events.AddHandler(EVENT_MOUSE_UP, value);
  166. }
  167. remove
  168. {
  169. base.Events.RemoveHandler(EVENT_MOUSE_UP, value);
  170. }
  171. }
  172. /// <summary>
  173. /// 触发鼠标弹起事件
  174. /// </summary>
  175. /// <param name="e">数据</param>
  176. protected virtual void OnMouseUp(MouseEventArgs e)
  177. {
  178. MouseEventHandler handler = base.Events[EVENT_MOUSE_UP] as MouseEventHandler;
  179. if (handler != null)
  180. handler(this, e);
  181. }
  182. private static readonly object EVENT_MOUSE_MOVE = new object();
  183. /// <summary>
  184. /// 鼠标移动事件
  185. /// </summary>
  186. public event MouseEventHandler MouseMove
  187. {
  188. add
  189. {
  190. base.Events.AddHandler(EVENT_MOUSE_MOVE, value);
  191. }
  192. remove
  193. {
  194. base.Events.RemoveHandler(EVENT_MOUSE_MOVE, value);
  195. }
  196. }
  197. /// <summary>
  198. /// 触发鼠标移动事件
  199. /// </summary>
  200. /// <param name="e">数据</param>
  201. protected virtual void OnMouseMove(MouseEventArgs e)
  202. {
  203. MouseEventHandler handler = base.Events[EVENT_MOUSE_MOVE] as MouseEventHandler;
  204. if (handler != null)
  205. handler(this, e);
  206. }
  207. private static readonly object EVENT_CLICK = new object();
  208. /// <summary>
  209. /// 单击事件
  210. /// </summary>
  211. public event EventHandler Click
  212. {
  213. add
  214. {
  215. base.Events.AddHandler(EVENT_CLICK, value);
  216. }
  217. remove
  218. {
  219. base.Events.RemoveHandler(EVENT_CLICK, value);
  220. }
  221. }
  222. /// <summary>
  223. /// 触发单击事件
  224. /// </summary>
  225. /// <param name="e">数据</param>
  226. protected virtual void OnClick(EventArgs e)
  227. {
  228. EventHandler handler = base.Events[EVENT_CLICK] as EventHandler;
  229. if (handler != null)
  230. handler(this, e);
  231. }
  232. private static readonly object EVENT_DOUBLE_CLICK = new object();
  233. /// <summary>
  234. /// 双击事件
  235. /// </summary>
  236. public event EventHandler DoubleClick
  237. {
  238. add
  239. {
  240. base.Events.AddHandler(EVENT_DOUBLE_CLICK, value);
  241. }
  242. remove
  243. {
  244. base.Events.RemoveHandler(EVENT_DOUBLE_CLICK, value);
  245. }
  246. }
  247. /// <summary>
  248. /// 触发双击事件
  249. /// </summary>
  250. /// <param name="e">数据</param>
  251. protected virtual void OnDoubleClick(EventArgs e)
  252. {
  253. EventHandler handler = base.Events[EVENT_DOUBLE_CLICK] as EventHandler;
  254. if (handler != null)
  255. handler(this, e);
  256. }
  257. private static readonly object EVENT_PAINT = new object();
  258. /// <summary>
  259. /// 渲染事件
  260. /// </summary>
  261. public event PaintEventHandler Paint
  262. {
  263. add
  264. {
  265. base.Events.AddHandler(EVENT_PAINT, value);
  266. }
  267. remove
  268. {
  269. base.Events.RemoveHandler(EVENT_PAINT, value);
  270. }
  271. }
  272. /// <summary>
  273. /// 触发渲染事件
  274. /// </summary>
  275. /// <param name="key">要引发的事件</param>
  276. /// <param name="e">数据</param>
  277. protected void RaisePaintEvent(object key, PaintEventArgs e)
  278. {
  279. PaintEventHandler handler = base.Events[EVENT_PAINT] as PaintEventHandler;
  280. if (handler != null)
  281. handler(this, e);
  282. }
  283. }
  284. }