ChatListBox.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. namespace LYFZ.ComponentLibrary.ChatListControl
  10. {
  11. [ToolboxBitmap(typeof(ListBox))]
  12. public class ChatListBox : Control
  13. {
  14. public delegate void ChatListEventHandler(object sender, ChatListEventArgs e);
  15. public delegate void DragListEventHandler(object sender, DragListEventArgs e);
  16. private ContextMenuStrip subItemMenu;
  17. private ContextMenuStrip listsubItemMenu;
  18. private ChatListItemIcon iconSizeMode;
  19. private ChatListItemCollection items;
  20. private ChatListSubItem selectSubItem;
  21. private Color arrowColor = Color.FromArgb(101, 103, 103);
  22. private Color itemColor = Color.Transparent;
  23. private Color subItemColor = Color.Transparent;
  24. private Color itemMouseOnColor = Color.FromArgb(150, 230, 238, 241);
  25. private Color subItemMouseOnColor = Color.FromArgb(200, 252, 240, 193);
  26. private Color subItemSelectColor = Color.FromArgb(200, 252, 236, 172);
  27. private Point m_ptMousePos;
  28. public ChatListVScroll chatVScroll;
  29. private ChatListItem m_mouseOnItem;
  30. private bool m_bOnMouseEnterHeaded;
  31. private ChatListSubItem m_mouseOnSubItem;
  32. private bool MouseDowns;
  33. private ChatListSubItem MouseDowmSubItems;
  34. private int CursorY;
  35. private bool MouseMoveItems;
  36. private IContainer components = null;
  37. [Category("子项操作"), Description("用鼠标单击子项时发生")]
  38. public event ChatListBox.ChatListEventHandler ClickSubItem;
  39. [Category("子项操作"), Description("用鼠标双击子项时发生")]
  40. public event ChatListBox.ChatListEventHandler DoubleClickSubItem;
  41. [Category("子项操作"), Description("在鼠标进入子项中的头像时发生")]
  42. public event ChatListBox.ChatListEventHandler MouseEnterHead;
  43. [Category("子项操作"), Description("在鼠标离开子项中的头像时发生")]
  44. public event ChatListBox.ChatListEventHandler MouseLeaveHead;
  45. [Category("子项操作"), Description("拖动子项操作完成后发生")]
  46. public event ChatListBox.DragListEventHandler DragSubItemDrop;
  47. #region 属性
  48. [Category("行为"), Description("当用户右击分组时显示的快捷菜单。")]
  49. public ContextMenuStrip SubItemMenu
  50. {
  51. get
  52. {
  53. return this.subItemMenu;
  54. }
  55. set
  56. {
  57. if (this.subItemMenu != value)
  58. {
  59. this.subItemMenu = value;
  60. }
  61. }
  62. }
  63. [Category("行为"), Description("当用户右击好友时显示的快捷菜单。")]
  64. public ContextMenuStrip ListSubItemMenu
  65. {
  66. get
  67. {
  68. return this.listsubItemMenu;
  69. }
  70. set
  71. {
  72. if (this.listsubItemMenu != value)
  73. {
  74. this.listsubItemMenu = value;
  75. }
  76. }
  77. }
  78. [Category("Appearance"), DefaultValue(ChatListItemIcon.Large), Description("与列表关联的图标模式")]
  79. public ChatListItemIcon IconSizeMode
  80. {
  81. get
  82. {
  83. return this.iconSizeMode;
  84. }
  85. set
  86. {
  87. if (this.iconSizeMode == value)
  88. {
  89. return;
  90. }
  91. this.iconSizeMode = value;
  92. base.Invalidate();
  93. }
  94. }
  95. [Category("Data"), Description("列表框中的项"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  96. public ChatListItemCollection Items
  97. {
  98. get
  99. {
  100. if (this.items == null)
  101. {
  102. this.items = new ChatListItemCollection(this);
  103. }
  104. return this.items;
  105. }
  106. }
  107. [Browsable(false)]
  108. public ChatListSubItem SelectSubItem
  109. {
  110. get
  111. {
  112. return this.selectSubItem;
  113. }
  114. }
  115. [Category("颜色"), DefaultValue(typeof(Color), "50, 224, 239, 235"), Description("滚动条的背景颜色")]
  116. public Color ScrollBackColor
  117. {
  118. get
  119. {
  120. return this.chatVScroll.BackColor;
  121. }
  122. set
  123. {
  124. this.chatVScroll.BackColor = value;
  125. }
  126. }
  127. [Category("颜色"), DefaultValue(typeof(Color), "100, 110, 111, 112"), Description("滚动条滑块默认情况下的颜色")]
  128. public Color ScrollSliderDefaultColor
  129. {
  130. get
  131. {
  132. return this.chatVScroll.SliderDefaultColor;
  133. }
  134. set
  135. {
  136. this.chatVScroll.SliderDefaultColor = value;
  137. }
  138. }
  139. [Category("颜色"), DefaultValue(typeof(Color), "200, 110, 111, 112"), Description("滚动条滑块被点击或者鼠标移动到上面时候的颜色")]
  140. public Color ScrollSliderDownColor
  141. {
  142. get
  143. {
  144. return this.chatVScroll.SliderDownColor;
  145. }
  146. set
  147. {
  148. this.chatVScroll.SliderDownColor = value;
  149. }
  150. }
  151. [Category("颜色"), DefaultValue(typeof(Color), "Transparent"), Description("滚动条箭头的背景颜色")]
  152. public Color ScrollArrowBackColor
  153. {
  154. get
  155. {
  156. return this.chatVScroll.ArrowBackColor;
  157. }
  158. set
  159. {
  160. this.chatVScroll.ArrowBackColor = value;
  161. }
  162. }
  163. [Category("颜色"), DefaultValue(typeof(Color), "200, 148, 150, 151"), Description("滚动条箭头的颜色")]
  164. public Color ScrollArrowColor
  165. {
  166. get
  167. {
  168. return this.chatVScroll.ArrowColor;
  169. }
  170. set
  171. {
  172. this.chatVScroll.ArrowColor = value;
  173. }
  174. }
  175. [Category("颜色"), DefaultValue(typeof(Color), "101, 103, 103"), Description("列表项上面的箭头的颜色")]
  176. public Color ArrowColor
  177. {
  178. get
  179. {
  180. return this.arrowColor;
  181. }
  182. set
  183. {
  184. if (this.arrowColor == value)
  185. {
  186. return;
  187. }
  188. this.arrowColor = value;
  189. base.Invalidate();
  190. }
  191. }
  192. [Category("颜色"), DefaultValue(typeof(Color), "Transparent"), Description("列表项的背景色")]
  193. public Color ItemColor
  194. {
  195. get
  196. {
  197. return this.itemColor;
  198. }
  199. set
  200. {
  201. if (this.itemColor == value)
  202. {
  203. return;
  204. }
  205. this.itemColor = value;
  206. }
  207. }
  208. [Category("颜色"), DefaultValue(typeof(Color), "Transparent"), Description("列表子项的背景色")]
  209. public Color SubItemColor
  210. {
  211. get
  212. {
  213. return this.subItemColor;
  214. }
  215. set
  216. {
  217. if (this.subItemColor == value)
  218. {
  219. return;
  220. }
  221. this.subItemColor = value;
  222. }
  223. }
  224. [Category("颜色"), DefaultValue(typeof(Color), "150, 230, 238, 241"), Description("当鼠标移动到列表项上面的颜色")]
  225. public Color ItemMouseOnColor
  226. {
  227. get
  228. {
  229. return this.itemMouseOnColor;
  230. }
  231. set
  232. {
  233. this.itemMouseOnColor = value;
  234. }
  235. }
  236. [Category("颜色"), DefaultValue(typeof(Color), "200, 252, 240, 193"), Description("当鼠标移动到子项上面的颜色")]
  237. public Color SubItemMouseOnColor
  238. {
  239. get
  240. {
  241. return this.subItemMouseOnColor;
  242. }
  243. set
  244. {
  245. this.subItemMouseOnColor = value;
  246. }
  247. }
  248. [Category("颜色"), DefaultValue(typeof(Color), "200, 252, 236, 172"), Description("当列表子项被选中时候的颜色")]
  249. public Color SubItemSelectColor
  250. {
  251. get
  252. {
  253. return this.subItemSelectColor;
  254. }
  255. set
  256. {
  257. this.subItemSelectColor = value;
  258. }
  259. }
  260. bool isDescription = true;
  261. /// <summary>
  262. /// 是否显示功能说明文字
  263. /// </summary>
  264. [Category("功能"), DefaultValue(typeof(bool), "true"), Description("是否显示功能说明文字")]
  265. public bool IsDescription
  266. {
  267. get
  268. {
  269. return this.isDescription;
  270. }
  271. set
  272. {
  273. this.isDescription = value;
  274. }
  275. }
  276. #endregion
  277. public ChatListBox()
  278. {
  279. this.InitializeComponent();
  280. base.SetStyle(ControlStyles.ResizeRedraw, true);
  281. base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  282. base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  283. base.SetStyle(ControlStyles.UserPaint, true);
  284. base.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  285. base.ResizeRedraw = true;
  286. base.Size = new Size(150, 250);
  287. this.iconSizeMode = ChatListItemIcon.Large;
  288. this.Font = new Font("微软雅黑", 10.5f, FontStyle.Regular, GraphicsUnit.Point, 134);
  289. this.ForeColor = Color.Black;
  290. this.items = new ChatListItemCollection(this);
  291. this.chatVScroll = new ChatListVScroll(this);
  292. this.BackColor = Color.FromArgb(50, 255, 255, 255);
  293. }
  294. protected virtual void OnClickSubItem(ChatListEventArgs e)
  295. {
  296. if (this.ClickSubItem != null)
  297. {
  298. this.ClickSubItem(this, e);
  299. }
  300. }
  301. protected virtual void OnDoubleClickSubItem(ChatListEventArgs e)
  302. {
  303. if (this.DoubleClickSubItem != null)
  304. {
  305. this.DoubleClickSubItem(this, e);
  306. }
  307. }
  308. protected virtual void OnMouseEnterHead(ChatListEventArgs e)
  309. {
  310. if (this.MouseEnterHead != null)
  311. {
  312. this.MouseEnterHead(this, e);
  313. }
  314. }
  315. protected virtual void OnMouseLeaveHead(ChatListEventArgs e)
  316. {
  317. if (this.MouseLeaveHead != null)
  318. {
  319. this.MouseLeaveHead(this, e);
  320. }
  321. }
  322. protected virtual void OnDragSubItemDrop(DragListEventArgs e)
  323. {
  324. if (this.DragSubItemDrop != null)
  325. {
  326. this.DragSubItemDrop(this, e);
  327. }
  328. }
  329. protected override void OnMouseUp(MouseEventArgs e)
  330. {
  331. if (e.Button == MouseButtons.Left)
  332. {
  333. this.chatVScroll.IsMouseDown = false;
  334. }
  335. this.MouseDowns = false;
  336. if (e.Button == MouseButtons.Left)
  337. {
  338. int i = 0;
  339. int Len = this.items.Count;
  340. while (i < Len)
  341. {
  342. if (this.items[i].Bounds.Contains(this.m_ptMousePos))
  343. {
  344. if (!this.items[i].IsOpen && this.MouseMoveItems && this.m_mouseOnItem != this.MouseDowmSubItems.OwnerListItem)
  345. {
  346. ChatListSubItem chatQSubItem = this.MouseDowmSubItems.Clone();
  347. this.MouseDowmSubItems.OwnerListItem.SubItems.Remove(this.MouseDowmSubItems);
  348. this.MouseDowmSubItems.OwnerListItem.IsOpen = true;
  349. this.MouseDowmSubItems.OwnerListItem = this.m_mouseOnItem;
  350. this.m_mouseOnItem.SubItems.AddAccordingToStatus(this.MouseDowmSubItems);
  351. this.m_mouseOnItem.IsOpen = true;
  352. this.OnDragSubItemDrop(new DragListEventArgs(chatQSubItem, this.MouseDowmSubItems));
  353. }
  354. }
  355. else
  356. {
  357. if (this.MouseDowmSubItems != null)
  358. {
  359. this.MouseDowmSubItems.OwnerListItem.IsOpen = true;
  360. }
  361. }
  362. i++;
  363. }
  364. }
  365. this.MouseMoveItems = false;
  366. this.MouseDowmSubItems = null;
  367. base.OnMouseUp(e);
  368. }
  369. protected override void OnMouseDown(MouseEventArgs e)
  370. {
  371. base.Focus();
  372. this.m_ptMousePos = e.Location;
  373. if (this.chatVScroll.SliderBounds.Contains(this.m_ptMousePos))
  374. {
  375. if (e.Button == MouseButtons.Left)
  376. {
  377. this.chatVScroll.IsMouseDown = true;
  378. this.chatVScroll.MouseDownY = e.Y;
  379. }
  380. }
  381. else
  382. {
  383. foreach (ChatListItem item in (IEnumerable)this.items)
  384. {
  385. if(item.Equals(m_mouseOnItem))
  386. // if (item.Bounds.Contains(this.m_ptMousePos))
  387. {
  388. // if (!item.IsOpen)
  389. // {
  390. this.selectSubItem = null;
  391. base.Invalidate();
  392. if (e.Button == MouseButtons.Left)
  393. {
  394. item.IsOpen = !item.IsOpen;
  395. }
  396. else
  397. {
  398. if (this.SubItemMenu != null)
  399. {
  400. this.SubItemMenu.Show(this, this.m_ptMousePos.X, this.m_ptMousePos.Y);
  401. }
  402. }
  403. // return;
  404. // }
  405. }else{
  406. //----
  407. foreach (ChatListSubItem subItem in (IEnumerable)item.SubItems)
  408. {
  409. if(subItem==m_mouseOnSubItem)
  410. //if (subItem.Bounds.Contains(this.m_ptMousePos))
  411. {
  412. this.selectSubItem = subItem;
  413. base.Invalidate();
  414. if (e.Button == MouseButtons.Left)
  415. {
  416. this.CursorY = Cursor.Position.Y;
  417. this.MouseDowns = true;
  418. this.MouseDowmSubItems = subItem;
  419. }
  420. else
  421. {
  422. if (this.ListSubItemMenu != null)
  423. {
  424. this.ListSubItemMenu.Show(this, this.m_ptMousePos.X, this.m_ptMousePos.Y);
  425. }
  426. }
  427. return;
  428. }
  429. }
  430. //---------
  431. // if (item == m_mouseOnItem)
  432. // if (new Rectangle(0, item.Bounds.Top, base.Width, 20).Contains(this.m_ptMousePos))
  433. //{
  434. // this.selectSubItem = null;
  435. // base.Invalidate();
  436. // if (e.Button == MouseButtons.Left)
  437. // {
  438. // item.IsOpen = !item.IsOpen;
  439. // }
  440. // else
  441. // {
  442. // if (this.SubItemMenu != null)
  443. // {
  444. // this.SubItemMenu.Show(this, this.m_ptMousePos.X, this.m_ptMousePos.Y);
  445. // }
  446. // }
  447. // return;
  448. //}
  449. ///------
  450. }
  451. }
  452. }
  453. base.OnMouseDown(e);
  454. }
  455. protected override void OnMouseWheel(MouseEventArgs e)
  456. {
  457. if (e.Delta > 0)
  458. {
  459. this.chatVScroll.Value -= 50;
  460. }
  461. if (e.Delta < 0)
  462. {
  463. this.chatVScroll.Value += 50;
  464. }
  465. base.OnMouseWheel(e);
  466. }
  467. protected override void OnPaint(PaintEventArgs e)
  468. {
  469. Graphics g = e.Graphics;
  470. g.SmoothingMode = SmoothingMode.HighQuality;
  471. g.PixelOffsetMode = PixelOffsetMode.HighQuality;
  472. g.TranslateTransform(0f, (float)(-(float)this.chatVScroll.Value));
  473. int SubItemWidth = this.chatVScroll.ShouldBeDraw ? (base.Width - 9) : base.Width;
  474. Rectangle rectItem = new Rectangle(0, 1, SubItemWidth, 25);
  475. Rectangle rectSubItem = new Rectangle(0, 26, SubItemWidth, (int)this.iconSizeMode);
  476. SolidBrush sb = new SolidBrush(this.itemColor);
  477. try
  478. {
  479. int i = 0;
  480. int lenItem = this.items.Count;
  481. while (i < lenItem)
  482. {
  483. this.DrawItem(g, this.items[i], rectItem, sb);
  484. if (this.items[i].IsOpen)
  485. {
  486. rectSubItem.Y = rectItem.Bottom + 1;
  487. int j = 0;
  488. int lenSubItem = this.items[i].SubItems.Count;
  489. while (j < lenSubItem)
  490. {
  491. this.DrawSubItem(g, this.items[i].SubItems[j], ref rectSubItem, sb);
  492. rectSubItem.Y = rectSubItem.Bottom + 1;
  493. rectSubItem.Height = (int)this.iconSizeMode;
  494. j++;
  495. }
  496. rectItem.Height = rectSubItem.Bottom - rectItem.Top - (int)this.iconSizeMode - 1;
  497. }
  498. this.items[i].Bounds = new Rectangle(rectItem.Location, rectItem.Size);
  499. rectItem.Y = rectItem.Bottom + 1;
  500. rectItem.Height = 25;
  501. i++;
  502. }
  503. g.ResetTransform();
  504. this.chatVScroll.VirtualHeight = rectItem.Bottom - 26;
  505. if (this.chatVScroll.ShouldBeDraw)
  506. {
  507. this.chatVScroll.ReDrawScroll(g);
  508. }
  509. }
  510. finally
  511. {
  512. sb.Dispose();
  513. }
  514. base.OnPaint(e);
  515. }
  516. protected override void OnCreateControl()
  517. {
  518. new System.Threading.Thread((ThreadStart)delegate
  519. {
  520. Rectangle rectReDraw = new Rectangle(0, 0, base.Width, base.Height);
  521. while (true)
  522. {
  523. int i = 0;
  524. int lenI = this.items.Count;
  525. while (i < lenI)
  526. {
  527. if (this.items[i].IsOpen)
  528. {
  529. int j = 0;
  530. int lenJ = this.items[i].SubItems.Count;
  531. while (j < lenJ)
  532. {
  533. if (this.items[i].SubItems[j].IsTwinkle)
  534. {
  535. this.items[i].SubItems[j].IsTwinkleHide = !this.items[i].SubItems[j].IsTwinkleHide;
  536. }
  537. rectReDraw.Y = this.items[i].SubItems[j].Bounds.Y - this.chatVScroll.Value;
  538. rectReDraw.Height = this.items[i].SubItems[j].Bounds.Height;
  539. base.Invalidate(rectReDraw);
  540. j++;
  541. }
  542. }
  543. else
  544. {
  545. rectReDraw.Y = this.items[i].Bounds.Y - this.chatVScroll.Value;
  546. rectReDraw.Height = this.items[i].Bounds.Height;
  547. if (this.items[i].TwinkleSubItemNumber > 0)
  548. {
  549. this.items[i].IsTwinkleHide = !this.items[i].IsTwinkleHide;
  550. }
  551. base.Invalidate(rectReDraw);
  552. }
  553. i++;
  554. }
  555. Thread.Sleep(210);
  556. }
  557. })
  558. {
  559. IsBackground = true
  560. }.Start();
  561. base.OnCreateControl();
  562. }
  563. protected override void OnMouseMove(MouseEventArgs e)
  564. {
  565. this.m_ptMousePos = e.Location;
  566. if (this.chatVScroll.IsMouseDown)
  567. {
  568. this.chatVScroll.MoveSliderFromLocation(e.Y);
  569. return;
  570. }
  571. if (this.chatVScroll.ShouldBeDraw)
  572. {
  573. if (this.chatVScroll.Bounds.Contains(this.m_ptMousePos))
  574. {
  575. this.ClearItemMouseOn();
  576. this.ClearSubItemMouseOn();
  577. this.chatVScroll.IsMouseOnSlider = true;
  578. this.chatVScroll.IsMouseOnUp = true;
  579. this.chatVScroll.IsMouseOnDown = true;
  580. return;
  581. }
  582. this.chatVScroll.ClearAllMouseOn();
  583. }
  584. this.m_ptMousePos.Y = this.m_ptMousePos.Y + this.chatVScroll.Value;
  585. int i = 0;
  586. int Len = this.items.Count;
  587. while (i < Len)
  588. {
  589. if (this.items[i].Bounds.Contains(this.m_ptMousePos))
  590. {
  591. if (this.items[i].IsOpen)
  592. {
  593. int lenSubItem = this.items[i].SubItems.Count;
  594. #region 鼠标拖动子项时移动子项位置
  595. int j = 0;
  596. while (j < lenSubItem)
  597. {
  598. if (this.items[i].SubItems[j].Bounds.Contains(this.m_ptMousePos))
  599. {
  600. if (this.m_mouseOnSubItem != null)
  601. {
  602. if (this.items[i].SubItems[j].HeadRect.Contains(this.m_ptMousePos))
  603. {
  604. if (!this.m_bOnMouseEnterHeaded)
  605. {
  606. this.OnMouseEnterHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
  607. this.m_bOnMouseEnterHeaded = true;
  608. }
  609. }
  610. else
  611. {
  612. if (this.m_bOnMouseEnterHeaded)
  613. {
  614. this.OnMouseLeaveHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
  615. this.m_bOnMouseEnterHeaded = false;
  616. }
  617. }
  618. //鼠标拖动子项时移动子项位置
  619. if (this.MouseDowns && Math.Abs(this.CursorY - Cursor.Position.Y) > 4)
  620. {
  621. //for (int z = 0; z < this.Items.Count; z++)
  622. //{
  623. // if (this.Items[z].IsOpen)
  624. // {
  625. // this.Items[z].IsOpen = false;
  626. // }
  627. //}
  628. //this.m_mouseOnSubItem.OwnerListItem.IsOpen = false;
  629. //this.MouseMoveItems = true;
  630. //Color color = Color.FromArgb(250, (int)this.SubItemSelectColor.R, (int)this.SubItemSelectColor.G, (int)this.SubItemSelectColor.B);
  631. //string strDraw = this.m_mouseOnSubItem.DisplayName;
  632. //Size szFont = TextRenderer.MeasureText(strDraw, this.Font);
  633. //int bmpWidth = 45 + szFont.Width + 10;
  634. //int bmpHeight = 45;
  635. //Bitmap bmp = new Bitmap(bmpWidth * 2, bmpHeight * 2);
  636. //Graphics g = Graphics.FromImage(bmp);
  637. //g.FillRectangle(new SolidBrush(color), bmpWidth, bmpHeight, bmpWidth, bmpHeight);
  638. //g.DrawImage(this.m_mouseOnSubItem.HeadImage, bmpWidth, bmpHeight, 45, 45);
  639. //if (szFont.Width > 0)
  640. //{
  641. // g.DrawString(strDraw, this.Font, Brushes.Black, (float)(bmpWidth + bmpHeight + 5), (float)(bmpHeight + (bmpHeight - szFont.Height) / 2));
  642. //}
  643. //else
  644. //{
  645. // g.DrawString(this.m_mouseOnSubItem.NicName, this.Font, Brushes.Black, (float)(bmpWidth + bmpHeight + 5), (float)(bmpHeight + (bmpHeight - szFont.Height) / 2));
  646. //}
  647. //Cursor cur = new Cursor(bmp.GetHicon());
  648. //Cursor.Current = cur;
  649. }
  650. //-----
  651. }
  652. if (this.items[i].SubItems[j].Equals(this.m_mouseOnSubItem))
  653. {
  654. return;
  655. }
  656. this.ClearSubItemMouseOn();
  657. this.ClearItemMouseOn();
  658. this.m_mouseOnSubItem = this.items[i].SubItems[j];
  659. base.Invalidate(new Rectangle(this.m_mouseOnSubItem.Bounds.X, this.m_mouseOnSubItem.Bounds.Y - this.chatVScroll.Value, this.m_mouseOnSubItem.Bounds.Width, this.m_mouseOnSubItem.Bounds.Height));
  660. return;
  661. }
  662. else
  663. {
  664. j++;
  665. }
  666. }
  667. #endregion
  668. this.ClearSubItemMouseOn();
  669. if (new Rectangle(0, this.items[i].Bounds.Top - this.chatVScroll.Value, base.Width, 20).Contains(e.Location))
  670. {
  671. if (this.items[i].Equals(this.m_mouseOnItem))
  672. {
  673. return;
  674. }
  675. this.ClearItemMouseOn();
  676. this.m_mouseOnItem = this.items[i];
  677. base.Invalidate(new Rectangle(this.m_mouseOnItem.Bounds.X, this.m_mouseOnItem.Bounds.Y - this.chatVScroll.Value, this.m_mouseOnItem.Bounds.Width, this.m_mouseOnItem.Bounds.Height));
  678. return;
  679. }
  680. }
  681. else
  682. {
  683. if (this.items[i].Equals(this.m_mouseOnItem))
  684. {
  685. return;
  686. }
  687. this.ClearItemMouseOn();
  688. this.ClearSubItemMouseOn();
  689. this.m_mouseOnItem = this.items[i];
  690. base.Invalidate(new Rectangle(this.m_mouseOnItem.Bounds.X, this.m_mouseOnItem.Bounds.Y - this.chatVScroll.Value, this.m_mouseOnItem.Bounds.Width, this.m_mouseOnItem.Bounds.Height));
  691. return;
  692. }
  693. }
  694. i++;
  695. }
  696. this.ClearItemMouseOn();
  697. this.ClearSubItemMouseOn();
  698. base.OnMouseMove(e);
  699. }
  700. protected override void OnMouseLeave(EventArgs e)
  701. {
  702. this.ClearItemMouseOn();
  703. this.ClearSubItemMouseOn();
  704. this.chatVScroll.ClearAllMouseOn();
  705. if (this.m_bOnMouseEnterHeaded)
  706. {
  707. this.OnMouseLeaveHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
  708. this.m_bOnMouseEnterHeaded = false;
  709. }
  710. base.OnMouseLeave(e);
  711. }
  712. protected override void OnClick(EventArgs e)
  713. {
  714. if (this.chatVScroll.IsMouseDown)
  715. {
  716. return;
  717. }
  718. //if (!this.chatVScroll.ShouldBeDraw || !this.chatVScroll.Bounds.Contains(this.m_ptMousePos))
  719. //{
  720. // base.OnClick(e);
  721. // return;
  722. //}
  723. if (this.chatVScroll.UpBounds.Contains(this.m_ptMousePos))
  724. {
  725. this.chatVScroll.Value -= 50;
  726. return;
  727. }
  728. if (this.chatVScroll.DownBounds.Contains(this.m_ptMousePos))
  729. {
  730. this.chatVScroll.Value += 50;
  731. return;
  732. }
  733. //if (!this.chatVScroll.SliderBounds.Contains(this.m_ptMousePos))
  734. //{
  735. // this.chatVScroll.MoveSliderToLocation(this.m_ptMousePos.Y);
  736. //}
  737. if (this.selectSubItem != null)
  738. {
  739. this.OnClickSubItem(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
  740. }
  741. }
  742. protected override void OnDoubleClick(EventArgs e)
  743. {
  744. this.OnClick(e);
  745. if (this.chatVScroll.Bounds.Contains(base.PointToClient(Control.MousePosition)))
  746. {
  747. return;
  748. }
  749. if (this.selectSubItem != null)
  750. {
  751. this.OnDoubleClickSubItem(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
  752. }
  753. base.OnDoubleClick(e);
  754. }
  755. protected virtual void DrawItem(Graphics g, ChatListItem item, Rectangle rectItem, SolidBrush sb)
  756. {
  757. StringFormat sf = new StringFormat();
  758. sf.LineAlignment = StringAlignment.Center;
  759. sf.SetTabStops(0f, new float[]
  760. {
  761. 20f
  762. });
  763. if (item.Equals(this.m_mouseOnItem))
  764. {
  765. sb.Color = this.itemMouseOnColor;
  766. }
  767. else
  768. {
  769. sb.Color = this.itemColor;
  770. }
  771. g.FillRectangle(sb, rectItem);
  772. if (item.IsOpen)
  773. {
  774. sb.Color = this.arrowColor;
  775. g.FillPolygon(sb, new Point[]
  776. {
  777. new Point(2, rectItem.Top + 11),
  778. new Point(12, rectItem.Top + 11),
  779. new Point(7, rectItem.Top + 16)
  780. });
  781. }
  782. else
  783. {
  784. sb.Color = this.arrowColor;
  785. g.FillPolygon(sb, new Point[]
  786. {
  787. new Point(5, rectItem.Top + 8),
  788. new Point(5, rectItem.Top + 18),
  789. new Point(10, rectItem.Top + 13)
  790. });
  791. if (item.TwinkleSubItemNumber > 0 && item.IsTwinkleHide)
  792. {
  793. return;
  794. }
  795. }
  796. string strItem = "\t" + item.Text;
  797. sb.Color = this.ForeColor;
  798. sf.Alignment = StringAlignment.Near;
  799. g.DrawString(strItem, this.Font, sb, rectItem, sf);
  800. Size Itemsize = TextRenderer.MeasureText(item.Text, this.Font);
  801. sf.Alignment = StringAlignment.Near;
  802. g.DrawString(string.Concat(new object[]
  803. {
  804. "[",
  805. //item.SubItems.GetOnLineNumber(),
  806. //"/",
  807. item.SubItems.Count,
  808. "]"
  809. }), this.Font, Brushes.Gray, new Rectangle(rectItem.X + Convert.ToInt32(Itemsize.Width) + 25, rectItem.Y, rectItem.Width - 15, rectItem.Height), sf);
  810. }
  811. protected virtual void DrawSubItem(Graphics g, ChatListSubItem subItem, ref Rectangle rectSubItem, SolidBrush sb)
  812. {
  813. if (subItem.Equals(this.selectSubItem))
  814. {
  815. rectSubItem.Height = 53;
  816. sb.Color = this.subItemSelectColor;
  817. g.FillRectangle(sb, rectSubItem);
  818. this.DrawHeadImage(g, subItem, rectSubItem);
  819. this.DrawLargeSubItem(g, subItem, rectSubItem);
  820. subItem.Bounds = new Rectangle(rectSubItem.Location, rectSubItem.Size);
  821. return;
  822. }
  823. if (subItem.Equals(this.m_mouseOnSubItem))
  824. {
  825. sb.Color = this.subItemMouseOnColor;
  826. }
  827. else
  828. {
  829. sb.Color = this.subItemColor;
  830. }
  831. g.FillRectangle(sb, rectSubItem);
  832. this.DrawHeadImage(g, subItem, rectSubItem);
  833. if (this.iconSizeMode == ChatListItemIcon.Large)
  834. {
  835. this.DrawLargeSubItem(g, subItem, rectSubItem);
  836. }
  837. else
  838. {
  839. this.DrawSmallSubItem(g, subItem, rectSubItem);
  840. }
  841. subItem.Bounds = new Rectangle(rectSubItem.Location, rectSubItem.Size);
  842. }
  843. /// <summary>
  844. /// 绘制图片
  845. /// </summary>
  846. /// <param name="g"></param>
  847. /// <param name="subItem"></param>
  848. /// <param name="rectSubItem"></param>
  849. protected virtual void DrawHeadImage(Graphics g, ChatListSubItem subItem, Rectangle rectSubItem)
  850. {
  851. if (subItem.IsTwinkle && subItem.IsTwinkleHide)
  852. {
  853. return;
  854. }
  855. int imageHeight = (rectSubItem.Height == 53) ? 40 : 20;
  856. subItem.HeadRect = new Rectangle(5, rectSubItem.Top + (rectSubItem.Height - imageHeight) / 2, imageHeight, imageHeight);
  857. if (subItem.HeadImage == null)
  858. {
  859. subItem.HeadImage = LYFZ.ComponentLibrary.Properties.Resources.tools_256px;
  860. }
  861. if (subItem.Status == ChatListSubItem.UserStatus.OffLine)
  862. {
  863. //subItem.HeadImage = GetGrayImage(subItem.HeadImage);
  864. //g.DrawImage(subItem.GetDarkImage(), subItem.HeadRect);//获取默认图标 离线图标
  865. // g.DrawImage(LYFZ.ComponentLibrary.Properties.Resources.Prohibit, new Rectangle(subItem.HeadRect.Right - 16, subItem.HeadRect.Bottom - 16, 16, 16));
  866. g.DrawImage(subItem.HeadImage, subItem.HeadRect);//获取默认图标
  867. }
  868. else
  869. {
  870. g.DrawImage(subItem.HeadImage, subItem.HeadRect);
  871. //if (subItem.Status == ChatListSubItem.UserStatus.QMe)
  872. //{
  873. // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
  874. //}
  875. //if (subItem.Status == ChatListSubItem.UserStatus.Away)
  876. //{
  877. // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
  878. //}
  879. //if (subItem.Status == ChatListSubItem.UserStatus.Busy)
  880. //{
  881. // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
  882. //}
  883. //if (subItem.Status == ChatListSubItem.UserStatus.DontDisturb)
  884. //{
  885. // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
  886. //}
  887. }
  888. if (subItem.Status != ChatListSubItem.UserStatus.OffLine)
  889. {
  890. //当选中当前子项目时显示的图标
  891. if (subItem.Equals(this.selectSubItem))
  892. {
  893. g.DrawImage(subItem.HeadImage, subItem.HeadRect.X - 2, subItem.HeadRect.Y - 2, 44, 44);
  894. return;
  895. }
  896. }
  897. Pen pen = new Pen(Color.FromArgb(200, 255, 255, 255));
  898. g.DrawRectangle(pen, subItem.HeadRect);
  899. }
  900. protected virtual void DrawLargeSubItem(Graphics g, ChatListSubItem subItem, Rectangle rectSubItem)
  901. {
  902. rectSubItem.Height = 53;
  903. string strDraw = subItem.DisplayName;
  904. Size szFont = TextRenderer.MeasureText(strDraw, this.Font);
  905. //TextRenderer.MeasureText(subItem.NicName, this.Font);
  906. StringFormat Sf = new StringFormat(StringFormatFlags.NoWrap);
  907. Sf.Trimming = StringTrimming.Word;
  908. Rectangle Rc = new Rectangle(new Point(rectSubItem.Height, rectSubItem.Top + 8), new Size(base.Width - 9 - rectSubItem.Height, szFont.Height));
  909. if (!IsDescription)
  910. {
  911. Rc.Location = new Point(Rc.Location.X, Rc.Location.Y+9);
  912. }
  913. // Rectangle NickNameRc = new Rectangle(new Point(rectSubItem.Height + szFont.Width, rectSubItem.Top + 8), new Size(base.Width - 9 - rectSubItem.Height - szFont.Width, szFont.Height));
  914. if (szFont.Width > 0)
  915. {
  916. g.DrawString(strDraw, this.Font, Brushes.Black, Rc, Sf);
  917. //g.DrawString("(" + subItem.NicName + ")", this.Font, Brushes.Gray, NickNameRc, Sf);
  918. }
  919. else
  920. {
  921. //Rectangle nkNameRc = new Rectangle(new Point(rectSubItem.Height, rectSubItem.Top + 8), new Size(base.Width - 9 - rectSubItem.Height, szFont.Height));
  922. //g.DrawString(subItem.NicName, this.Font, Brushes.Black, nkNameRc, Sf);
  923. g.DrawString(subItem.NicName, this.Font, Brushes.Black, Rc, Sf);
  924. }
  925. if (IsDescription)
  926. {
  927. Size MsgFont = TextRenderer.MeasureText(subItem.PersonalMsg, this.Font);
  928. Rectangle MsgRc = new Rectangle(new Point(rectSubItem.Height, rectSubItem.Top + 11 + this.Font.Height), new Size(base.Width - rectSubItem.Height, MsgFont.Height));
  929. Font PersonalMsgFont = new Font(this.Font.FontFamily, 8);
  930. g.DrawString(subItem.PersonalMsg, PersonalMsgFont, Brushes.Gray, MsgRc, Sf);
  931. }
  932. }
  933. protected virtual void DrawSmallSubItem(Graphics g, ChatListSubItem subItem, Rectangle rectSubItem)
  934. {
  935. rectSubItem.Height = 27;
  936. StringFormat sf = new StringFormat();
  937. sf.LineAlignment = StringAlignment.Center;
  938. sf.FormatFlags = StringFormatFlags.NoWrap;
  939. string strDraw = subItem.DisplayName;
  940. if (string.IsNullOrEmpty(strDraw))
  941. {
  942. strDraw = subItem.NicName;
  943. }
  944. Size szFont = TextRenderer.MeasureText(strDraw, this.Font);
  945. sf.SetTabStops(0f, new float[]
  946. {
  947. (float)rectSubItem.Height
  948. });
  949. g.DrawString("\t" + strDraw, this.Font, Brushes.Black, rectSubItem, sf);
  950. sf.SetTabStops(0f, new float[]
  951. {
  952. (float)(rectSubItem.Height + 5 + szFont.Width)
  953. });
  954. g.DrawString("\t" + subItem.PersonalMsg, this.Font, Brushes.Gray, rectSubItem, sf);
  955. }
  956. private void ClearItemMouseOn()
  957. {
  958. if (this.m_mouseOnItem != null)
  959. {
  960. int z = 0;
  961. if (this.chatVScroll.ShouldBeDraw)
  962. {
  963. z = 9;
  964. }
  965. base.Invalidate(new Rectangle(this.m_mouseOnItem.Bounds.X, this.m_mouseOnItem.Bounds.Y - this.chatVScroll.Value, this.m_mouseOnItem.Bounds.Width + z, this.m_mouseOnItem.Bounds.Height));
  966. this.m_mouseOnItem = null;
  967. }
  968. }
  969. private void ClearSubItemMouseOn()
  970. {
  971. if (this.m_mouseOnSubItem != null)
  972. {
  973. int z = 0;
  974. if (this.chatVScroll.ShouldBeDraw)
  975. {
  976. z = 9;
  977. }
  978. base.Invalidate(new Rectangle(this.m_mouseOnSubItem.Bounds.X, this.m_mouseOnSubItem.Bounds.Y - this.chatVScroll.Value, this.m_mouseOnSubItem.Bounds.Width + z, this.m_mouseOnSubItem.Bounds.Height));
  979. this.m_mouseOnSubItem = null;
  980. }
  981. }
  982. public ChatListSubItem[] GetSubItemsById(int userId)
  983. {
  984. List<ChatListSubItem> subItems = new List<ChatListSubItem>();
  985. int i = 0;
  986. int lenI = this.items.Count;
  987. while (i < lenI)
  988. {
  989. int j = 0;
  990. int lenJ = this.items[i].SubItems.Count;
  991. while (j < lenJ)
  992. {
  993. if (userId == this.items[i].SubItems[j].ID)
  994. {
  995. subItems.Add(this.items[i].SubItems[j]);
  996. }
  997. j++;
  998. }
  999. i++;
  1000. }
  1001. return subItems.ToArray();
  1002. }
  1003. public ChatListSubItem[] GetSubItemsByNicName(string nicName)
  1004. {
  1005. List<ChatListSubItem> subItems = new List<ChatListSubItem>();
  1006. int i = 0;
  1007. int lenI = this.items.Count;
  1008. while (i < lenI)
  1009. {
  1010. int j = 0;
  1011. int lenJ = this.items[i].SubItems.Count;
  1012. while (j < lenJ)
  1013. {
  1014. if (nicName == this.items[i].SubItems[j].NicName)
  1015. {
  1016. subItems.Add(this.items[i].SubItems[j]);
  1017. }
  1018. j++;
  1019. }
  1020. i++;
  1021. }
  1022. return subItems.ToArray();
  1023. }
  1024. public ChatListSubItem[] GetSubItemsByDisplayName(string displayName)
  1025. {
  1026. List<ChatListSubItem> subItems = new List<ChatListSubItem>();
  1027. int i = 0;
  1028. int lenI = this.items.Count;
  1029. while (i < lenI)
  1030. {
  1031. int j = 0;
  1032. int lenJ = this.items[i].SubItems.Count;
  1033. while (j < lenJ)
  1034. {
  1035. if (displayName == this.items[i].SubItems[j].DisplayName)
  1036. {
  1037. subItems.Add(this.items[i].SubItems[j]);
  1038. }
  1039. j++;
  1040. }
  1041. i++;
  1042. }
  1043. return subItems.ToArray();
  1044. }
  1045. public ChatListSubItem[] GetSubItemsByIp(string Ip)
  1046. {
  1047. List<ChatListSubItem> subItems = new List<ChatListSubItem>();
  1048. int i = 0;
  1049. int lenI = this.items.Count;
  1050. while (i < lenI)
  1051. {
  1052. int j = 0;
  1053. int lenJ = this.items[i].SubItems.Count;
  1054. while (j < lenJ)
  1055. {
  1056. if (Ip == this.items[i].SubItems[j].IpAddress)
  1057. {
  1058. subItems.Add(this.items[i].SubItems[j]);
  1059. }
  1060. j++;
  1061. }
  1062. i++;
  1063. }
  1064. return subItems.ToArray();
  1065. }
  1066. protected override void Dispose(bool disposing)
  1067. {
  1068. if (disposing && this.components != null)
  1069. {
  1070. this.components.Dispose();
  1071. }
  1072. base.Dispose(disposing);
  1073. }
  1074. private void InitializeComponent()
  1075. {
  1076. base.SuspendLayout();
  1077. base.ResumeLayout(false);
  1078. }
  1079. }
  1080. }