1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Threading;
- using System.Windows.Forms;
- namespace LYFZ.ComponentLibrary.ChatListControl
- {
- [ToolboxBitmap(typeof(ListBox))]
- public class ChatListBox : Control
- {
- public delegate void ChatListEventHandler(object sender, ChatListEventArgs e);
- public delegate void DragListEventHandler(object sender, DragListEventArgs e);
- private ContextMenuStrip subItemMenu;
- private ContextMenuStrip listsubItemMenu;
- private ChatListItemIcon iconSizeMode;
- private ChatListItemCollection items;
- private ChatListSubItem selectSubItem;
- private Color arrowColor = Color.FromArgb(101, 103, 103);
- private Color itemColor = Color.Transparent;
- private Color subItemColor = Color.Transparent;
- private Color itemMouseOnColor = Color.FromArgb(150, 230, 238, 241);
- private Color subItemMouseOnColor = Color.FromArgb(200, 252, 240, 193);
- private Color subItemSelectColor = Color.FromArgb(200, 252, 236, 172);
- private Point m_ptMousePos;
- public ChatListVScroll chatVScroll;
- private ChatListItem m_mouseOnItem;
- private bool m_bOnMouseEnterHeaded;
- private ChatListSubItem m_mouseOnSubItem;
- private bool MouseDowns;
- private ChatListSubItem MouseDowmSubItems;
- private int CursorY;
- private bool MouseMoveItems;
- private IContainer components = null;
- [Category("子项操作"), Description("用鼠标单击子项时发生")]
- public event ChatListBox.ChatListEventHandler ClickSubItem;
- [Category("子项操作"), Description("用鼠标双击子项时发生")]
- public event ChatListBox.ChatListEventHandler DoubleClickSubItem;
- [Category("子项操作"), Description("在鼠标进入子项中的头像时发生")]
- public event ChatListBox.ChatListEventHandler MouseEnterHead;
- [Category("子项操作"), Description("在鼠标离开子项中的头像时发生")]
- public event ChatListBox.ChatListEventHandler MouseLeaveHead;
- [Category("子项操作"), Description("拖动子项操作完成后发生")]
- public event ChatListBox.DragListEventHandler DragSubItemDrop;
- #region 属性
- [Category("行为"), Description("当用户右击分组时显示的快捷菜单。")]
- public ContextMenuStrip SubItemMenu
- {
- get
- {
- return this.subItemMenu;
- }
- set
- {
- if (this.subItemMenu != value)
- {
- this.subItemMenu = value;
- }
- }
- }
- [Category("行为"), Description("当用户右击好友时显示的快捷菜单。")]
- public ContextMenuStrip ListSubItemMenu
- {
- get
- {
- return this.listsubItemMenu;
- }
- set
- {
- if (this.listsubItemMenu != value)
- {
- this.listsubItemMenu = value;
- }
- }
- }
- [Category("Appearance"), DefaultValue(ChatListItemIcon.Large), Description("与列表关联的图标模式")]
- public ChatListItemIcon IconSizeMode
- {
- get
- {
- return this.iconSizeMode;
- }
- set
- {
- if (this.iconSizeMode == value)
- {
- return;
- }
- this.iconSizeMode = value;
- base.Invalidate();
- }
- }
- [Category("Data"), Description("列表框中的项"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- public ChatListItemCollection Items
- {
- get
- {
- if (this.items == null)
- {
- this.items = new ChatListItemCollection(this);
- }
- return this.items;
- }
- }
- [Browsable(false)]
- public ChatListSubItem SelectSubItem
- {
- get
- {
- return this.selectSubItem;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "50, 224, 239, 235"), Description("滚动条的背景颜色")]
- public Color ScrollBackColor
- {
- get
- {
- return this.chatVScroll.BackColor;
- }
- set
- {
- this.chatVScroll.BackColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "100, 110, 111, 112"), Description("滚动条滑块默认情况下的颜色")]
- public Color ScrollSliderDefaultColor
- {
- get
- {
- return this.chatVScroll.SliderDefaultColor;
- }
- set
- {
- this.chatVScroll.SliderDefaultColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "200, 110, 111, 112"), Description("滚动条滑块被点击或者鼠标移动到上面时候的颜色")]
- public Color ScrollSliderDownColor
- {
- get
- {
- return this.chatVScroll.SliderDownColor;
- }
- set
- {
- this.chatVScroll.SliderDownColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "Transparent"), Description("滚动条箭头的背景颜色")]
- public Color ScrollArrowBackColor
- {
- get
- {
- return this.chatVScroll.ArrowBackColor;
- }
- set
- {
- this.chatVScroll.ArrowBackColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "200, 148, 150, 151"), Description("滚动条箭头的颜色")]
- public Color ScrollArrowColor
- {
- get
- {
- return this.chatVScroll.ArrowColor;
- }
- set
- {
- this.chatVScroll.ArrowColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "101, 103, 103"), Description("列表项上面的箭头的颜色")]
- public Color ArrowColor
- {
- get
- {
- return this.arrowColor;
- }
- set
- {
- if (this.arrowColor == value)
- {
- return;
- }
- this.arrowColor = value;
- base.Invalidate();
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "Transparent"), Description("列表项的背景色")]
- public Color ItemColor
- {
- get
- {
- return this.itemColor;
- }
- set
- {
- if (this.itemColor == value)
- {
- return;
- }
- this.itemColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "Transparent"), Description("列表子项的背景色")]
- public Color SubItemColor
- {
- get
- {
- return this.subItemColor;
- }
- set
- {
- if (this.subItemColor == value)
- {
- return;
- }
- this.subItemColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "150, 230, 238, 241"), Description("当鼠标移动到列表项上面的颜色")]
- public Color ItemMouseOnColor
- {
- get
- {
- return this.itemMouseOnColor;
- }
- set
- {
- this.itemMouseOnColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "200, 252, 240, 193"), Description("当鼠标移动到子项上面的颜色")]
- public Color SubItemMouseOnColor
- {
- get
- {
- return this.subItemMouseOnColor;
- }
- set
- {
- this.subItemMouseOnColor = value;
- }
- }
- [Category("颜色"), DefaultValue(typeof(Color), "200, 252, 236, 172"), Description("当列表子项被选中时候的颜色")]
- public Color SubItemSelectColor
- {
- get
- {
- return this.subItemSelectColor;
- }
- set
- {
- this.subItemSelectColor = value;
- }
- }
- bool isDescription = true;
- /// <summary>
- /// 是否显示功能说明文字
- /// </summary>
- [Category("功能"), DefaultValue(typeof(bool), "true"), Description("是否显示功能说明文字")]
- public bool IsDescription
- {
- get
- {
- return this.isDescription;
- }
- set
- {
- this.isDescription = value;
- }
- }
- #endregion
- public ChatListBox()
- {
- this.InitializeComponent();
- base.SetStyle(ControlStyles.ResizeRedraw, true);
- base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- base.SetStyle(ControlStyles.UserPaint, true);
- base.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- base.ResizeRedraw = true;
- base.Size = new Size(150, 250);
- this.iconSizeMode = ChatListItemIcon.Large;
- this.Font = new Font("微软雅黑", 10.5f, FontStyle.Regular, GraphicsUnit.Point, 134);
- this.ForeColor = Color.Black;
- this.items = new ChatListItemCollection(this);
- this.chatVScroll = new ChatListVScroll(this);
- this.BackColor = Color.FromArgb(50, 255, 255, 255);
- }
- protected virtual void OnClickSubItem(ChatListEventArgs e)
- {
- if (this.ClickSubItem != null)
- {
- this.ClickSubItem(this, e);
- }
- }
- protected virtual void OnDoubleClickSubItem(ChatListEventArgs e)
- {
- if (this.DoubleClickSubItem != null)
- {
- this.DoubleClickSubItem(this, e);
- }
- }
- protected virtual void OnMouseEnterHead(ChatListEventArgs e)
- {
- if (this.MouseEnterHead != null)
- {
- this.MouseEnterHead(this, e);
- }
- }
- protected virtual void OnMouseLeaveHead(ChatListEventArgs e)
- {
- if (this.MouseLeaveHead != null)
- {
- this.MouseLeaveHead(this, e);
- }
- }
- protected virtual void OnDragSubItemDrop(DragListEventArgs e)
- {
- if (this.DragSubItemDrop != null)
- {
- this.DragSubItemDrop(this, e);
- }
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- this.chatVScroll.IsMouseDown = false;
- }
- this.MouseDowns = false;
- if (e.Button == MouseButtons.Left)
- {
- int i = 0;
- int Len = this.items.Count;
- while (i < Len)
- {
- if (this.items[i].Bounds.Contains(this.m_ptMousePos))
- {
- if (!this.items[i].IsOpen && this.MouseMoveItems && this.m_mouseOnItem != this.MouseDowmSubItems.OwnerListItem)
- {
- ChatListSubItem chatQSubItem = this.MouseDowmSubItems.Clone();
- this.MouseDowmSubItems.OwnerListItem.SubItems.Remove(this.MouseDowmSubItems);
- this.MouseDowmSubItems.OwnerListItem.IsOpen = true;
- this.MouseDowmSubItems.OwnerListItem = this.m_mouseOnItem;
- this.m_mouseOnItem.SubItems.AddAccordingToStatus(this.MouseDowmSubItems);
- this.m_mouseOnItem.IsOpen = true;
- this.OnDragSubItemDrop(new DragListEventArgs(chatQSubItem, this.MouseDowmSubItems));
- }
- }
- else
- {
- if (this.MouseDowmSubItems != null)
- {
- this.MouseDowmSubItems.OwnerListItem.IsOpen = true;
- }
- }
- i++;
- }
- }
- this.MouseMoveItems = false;
- this.MouseDowmSubItems = null;
- base.OnMouseUp(e);
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.Focus();
- this.m_ptMousePos = e.Location;
- if (this.chatVScroll.SliderBounds.Contains(this.m_ptMousePos))
- {
- if (e.Button == MouseButtons.Left)
- {
- this.chatVScroll.IsMouseDown = true;
- this.chatVScroll.MouseDownY = e.Y;
- }
- }
- else
- {
- foreach (ChatListItem item in (IEnumerable)this.items)
- {
- if(item.Equals(m_mouseOnItem))
- // if (item.Bounds.Contains(this.m_ptMousePos))
- {
- // if (!item.IsOpen)
- // {
- this.selectSubItem = null;
- base.Invalidate();
- if (e.Button == MouseButtons.Left)
- {
- item.IsOpen = !item.IsOpen;
- }
- else
- {
- if (this.SubItemMenu != null)
- {
- this.SubItemMenu.Show(this, this.m_ptMousePos.X, this.m_ptMousePos.Y);
- }
- }
- // return;
- // }
- }else{
- //----
- foreach (ChatListSubItem subItem in (IEnumerable)item.SubItems)
- {
- if(subItem==m_mouseOnSubItem)
- //if (subItem.Bounds.Contains(this.m_ptMousePos))
- {
- this.selectSubItem = subItem;
- base.Invalidate();
- if (e.Button == MouseButtons.Left)
- {
- this.CursorY = Cursor.Position.Y;
- this.MouseDowns = true;
- this.MouseDowmSubItems = subItem;
- }
- else
- {
- if (this.ListSubItemMenu != null)
- {
- this.ListSubItemMenu.Show(this, this.m_ptMousePos.X, this.m_ptMousePos.Y);
- }
- }
- return;
- }
- }
- //---------
- // if (item == m_mouseOnItem)
- // if (new Rectangle(0, item.Bounds.Top, base.Width, 20).Contains(this.m_ptMousePos))
- //{
- // this.selectSubItem = null;
- // base.Invalidate();
- // if (e.Button == MouseButtons.Left)
- // {
- // item.IsOpen = !item.IsOpen;
- // }
- // else
- // {
- // if (this.SubItemMenu != null)
- // {
- // this.SubItemMenu.Show(this, this.m_ptMousePos.X, this.m_ptMousePos.Y);
- // }
- // }
- // return;
- //}
- ///------
- }
- }
- }
- base.OnMouseDown(e);
- }
- protected override void OnMouseWheel(MouseEventArgs e)
- {
- if (e.Delta > 0)
- {
- this.chatVScroll.Value -= 50;
- }
- if (e.Delta < 0)
- {
- this.chatVScroll.Value += 50;
- }
- base.OnMouseWheel(e);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- g.SmoothingMode = SmoothingMode.HighQuality;
- g.PixelOffsetMode = PixelOffsetMode.HighQuality;
- g.TranslateTransform(0f, (float)(-(float)this.chatVScroll.Value));
- int SubItemWidth = this.chatVScroll.ShouldBeDraw ? (base.Width - 9) : base.Width;
- Rectangle rectItem = new Rectangle(0, 1, SubItemWidth, 25);
- Rectangle rectSubItem = new Rectangle(0, 26, SubItemWidth, (int)this.iconSizeMode);
- SolidBrush sb = new SolidBrush(this.itemColor);
- try
- {
- int i = 0;
- int lenItem = this.items.Count;
- while (i < lenItem)
- {
- this.DrawItem(g, this.items[i], rectItem, sb);
- if (this.items[i].IsOpen)
- {
- rectSubItem.Y = rectItem.Bottom + 1;
- int j = 0;
- int lenSubItem = this.items[i].SubItems.Count;
- while (j < lenSubItem)
- {
- this.DrawSubItem(g, this.items[i].SubItems[j], ref rectSubItem, sb);
- rectSubItem.Y = rectSubItem.Bottom + 1;
- rectSubItem.Height = (int)this.iconSizeMode;
- j++;
- }
- rectItem.Height = rectSubItem.Bottom - rectItem.Top - (int)this.iconSizeMode - 1;
- }
- this.items[i].Bounds = new Rectangle(rectItem.Location, rectItem.Size);
- rectItem.Y = rectItem.Bottom + 1;
- rectItem.Height = 25;
- i++;
- }
- g.ResetTransform();
- this.chatVScroll.VirtualHeight = rectItem.Bottom - 26;
- if (this.chatVScroll.ShouldBeDraw)
- {
- this.chatVScroll.ReDrawScroll(g);
- }
- }
- finally
- {
- sb.Dispose();
- }
- base.OnPaint(e);
- }
- protected override void OnCreateControl()
- {
- new System.Threading.Thread((ThreadStart)delegate
- {
- Rectangle rectReDraw = new Rectangle(0, 0, base.Width, base.Height);
- while (true)
- {
- int i = 0;
- int lenI = this.items.Count;
- while (i < lenI)
- {
- if (this.items[i].IsOpen)
- {
- int j = 0;
- int lenJ = this.items[i].SubItems.Count;
- while (j < lenJ)
- {
- if (this.items[i].SubItems[j].IsTwinkle)
- {
- this.items[i].SubItems[j].IsTwinkleHide = !this.items[i].SubItems[j].IsTwinkleHide;
- }
- rectReDraw.Y = this.items[i].SubItems[j].Bounds.Y - this.chatVScroll.Value;
- rectReDraw.Height = this.items[i].SubItems[j].Bounds.Height;
- base.Invalidate(rectReDraw);
- j++;
- }
- }
- else
- {
- rectReDraw.Y = this.items[i].Bounds.Y - this.chatVScroll.Value;
- rectReDraw.Height = this.items[i].Bounds.Height;
- if (this.items[i].TwinkleSubItemNumber > 0)
- {
- this.items[i].IsTwinkleHide = !this.items[i].IsTwinkleHide;
- }
- base.Invalidate(rectReDraw);
- }
- i++;
- }
- Thread.Sleep(210);
- }
- })
- {
- IsBackground = true
- }.Start();
- base.OnCreateControl();
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- this.m_ptMousePos = e.Location;
- if (this.chatVScroll.IsMouseDown)
- {
- this.chatVScroll.MoveSliderFromLocation(e.Y);
- return;
- }
- if (this.chatVScroll.ShouldBeDraw)
- {
- if (this.chatVScroll.Bounds.Contains(this.m_ptMousePos))
- {
- this.ClearItemMouseOn();
- this.ClearSubItemMouseOn();
- this.chatVScroll.IsMouseOnSlider = true;
- this.chatVScroll.IsMouseOnUp = true;
- this.chatVScroll.IsMouseOnDown = true;
- return;
- }
- this.chatVScroll.ClearAllMouseOn();
- }
- this.m_ptMousePos.Y = this.m_ptMousePos.Y + this.chatVScroll.Value;
- int i = 0;
- int Len = this.items.Count;
- while (i < Len)
- {
- if (this.items[i].Bounds.Contains(this.m_ptMousePos))
- {
- if (this.items[i].IsOpen)
- {
-
- int lenSubItem = this.items[i].SubItems.Count;
- #region 鼠标拖动子项时移动子项位置
- int j = 0;
- while (j < lenSubItem)
- {
- if (this.items[i].SubItems[j].Bounds.Contains(this.m_ptMousePos))
- {
- if (this.m_mouseOnSubItem != null)
- {
- if (this.items[i].SubItems[j].HeadRect.Contains(this.m_ptMousePos))
- {
- if (!this.m_bOnMouseEnterHeaded)
- {
- this.OnMouseEnterHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
- this.m_bOnMouseEnterHeaded = true;
- }
- }
- else
- {
- if (this.m_bOnMouseEnterHeaded)
- {
- this.OnMouseLeaveHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
- this.m_bOnMouseEnterHeaded = false;
- }
- }
- //鼠标拖动子项时移动子项位置
- if (this.MouseDowns && Math.Abs(this.CursorY - Cursor.Position.Y) > 4)
- {
- //for (int z = 0; z < this.Items.Count; z++)
- //{
- // if (this.Items[z].IsOpen)
- // {
- // this.Items[z].IsOpen = false;
- // }
- //}
- //this.m_mouseOnSubItem.OwnerListItem.IsOpen = false;
- //this.MouseMoveItems = true;
- //Color color = Color.FromArgb(250, (int)this.SubItemSelectColor.R, (int)this.SubItemSelectColor.G, (int)this.SubItemSelectColor.B);
- //string strDraw = this.m_mouseOnSubItem.DisplayName;
- //Size szFont = TextRenderer.MeasureText(strDraw, this.Font);
- //int bmpWidth = 45 + szFont.Width + 10;
- //int bmpHeight = 45;
- //Bitmap bmp = new Bitmap(bmpWidth * 2, bmpHeight * 2);
- //Graphics g = Graphics.FromImage(bmp);
- //g.FillRectangle(new SolidBrush(color), bmpWidth, bmpHeight, bmpWidth, bmpHeight);
- //g.DrawImage(this.m_mouseOnSubItem.HeadImage, bmpWidth, bmpHeight, 45, 45);
- //if (szFont.Width > 0)
- //{
- // g.DrawString(strDraw, this.Font, Brushes.Black, (float)(bmpWidth + bmpHeight + 5), (float)(bmpHeight + (bmpHeight - szFont.Height) / 2));
- //}
- //else
- //{
- // g.DrawString(this.m_mouseOnSubItem.NicName, this.Font, Brushes.Black, (float)(bmpWidth + bmpHeight + 5), (float)(bmpHeight + (bmpHeight - szFont.Height) / 2));
- //}
- //Cursor cur = new Cursor(bmp.GetHicon());
- //Cursor.Current = cur;
-
- }
- //-----
- }
- if (this.items[i].SubItems[j].Equals(this.m_mouseOnSubItem))
- {
- return;
- }
- this.ClearSubItemMouseOn();
- this.ClearItemMouseOn();
- this.m_mouseOnSubItem = this.items[i].SubItems[j];
- 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));
- return;
- }
- else
- {
- j++;
- }
- }
- #endregion
- this.ClearSubItemMouseOn();
- if (new Rectangle(0, this.items[i].Bounds.Top - this.chatVScroll.Value, base.Width, 20).Contains(e.Location))
- {
- if (this.items[i].Equals(this.m_mouseOnItem))
- {
- return;
- }
- this.ClearItemMouseOn();
- this.m_mouseOnItem = this.items[i];
- 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));
- return;
- }
- }
- else
- {
- if (this.items[i].Equals(this.m_mouseOnItem))
- {
- return;
- }
- this.ClearItemMouseOn();
- this.ClearSubItemMouseOn();
- this.m_mouseOnItem = this.items[i];
- 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));
- return;
- }
- }
- i++;
- }
- this.ClearItemMouseOn();
- this.ClearSubItemMouseOn();
- base.OnMouseMove(e);
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- this.ClearItemMouseOn();
- this.ClearSubItemMouseOn();
- this.chatVScroll.ClearAllMouseOn();
- if (this.m_bOnMouseEnterHeaded)
- {
- this.OnMouseLeaveHead(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
- this.m_bOnMouseEnterHeaded = false;
- }
- base.OnMouseLeave(e);
- }
- protected override void OnClick(EventArgs e)
- {
- if (this.chatVScroll.IsMouseDown)
- {
- return;
- }
- //if (!this.chatVScroll.ShouldBeDraw || !this.chatVScroll.Bounds.Contains(this.m_ptMousePos))
- //{
- // base.OnClick(e);
- // return;
- //}
- if (this.chatVScroll.UpBounds.Contains(this.m_ptMousePos))
- {
- this.chatVScroll.Value -= 50;
- return;
- }
- if (this.chatVScroll.DownBounds.Contains(this.m_ptMousePos))
- {
- this.chatVScroll.Value += 50;
- return;
- }
- //if (!this.chatVScroll.SliderBounds.Contains(this.m_ptMousePos))
- //{
- // this.chatVScroll.MoveSliderToLocation(this.m_ptMousePos.Y);
- //}
- if (this.selectSubItem != null)
- {
- this.OnClickSubItem(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
- }
- }
- protected override void OnDoubleClick(EventArgs e)
- {
- this.OnClick(e);
- if (this.chatVScroll.Bounds.Contains(base.PointToClient(Control.MousePosition)))
- {
- return;
- }
- if (this.selectSubItem != null)
- {
- this.OnDoubleClickSubItem(new ChatListEventArgs(this.m_mouseOnSubItem, this.selectSubItem));
- }
- base.OnDoubleClick(e);
- }
- protected virtual void DrawItem(Graphics g, ChatListItem item, Rectangle rectItem, SolidBrush sb)
- {
- StringFormat sf = new StringFormat();
- sf.LineAlignment = StringAlignment.Center;
- sf.SetTabStops(0f, new float[]
- {
- 20f
- });
- if (item.Equals(this.m_mouseOnItem))
- {
- sb.Color = this.itemMouseOnColor;
- }
- else
- {
- sb.Color = this.itemColor;
- }
- g.FillRectangle(sb, rectItem);
- if (item.IsOpen)
- {
- sb.Color = this.arrowColor;
- g.FillPolygon(sb, new Point[]
- {
- new Point(2, rectItem.Top + 11),
- new Point(12, rectItem.Top + 11),
- new Point(7, rectItem.Top + 16)
- });
- }
- else
- {
- sb.Color = this.arrowColor;
- g.FillPolygon(sb, new Point[]
- {
- new Point(5, rectItem.Top + 8),
- new Point(5, rectItem.Top + 18),
- new Point(10, rectItem.Top + 13)
- });
- if (item.TwinkleSubItemNumber > 0 && item.IsTwinkleHide)
- {
- return;
- }
- }
- string strItem = "\t" + item.Text;
- sb.Color = this.ForeColor;
- sf.Alignment = StringAlignment.Near;
- g.DrawString(strItem, this.Font, sb, rectItem, sf);
- Size Itemsize = TextRenderer.MeasureText(item.Text, this.Font);
- sf.Alignment = StringAlignment.Near;
- g.DrawString(string.Concat(new object[]
- {
- "[",
- //item.SubItems.GetOnLineNumber(),
- //"/",
- item.SubItems.Count,
- "]"
- }), this.Font, Brushes.Gray, new Rectangle(rectItem.X + Convert.ToInt32(Itemsize.Width) + 25, rectItem.Y, rectItem.Width - 15, rectItem.Height), sf);
- }
- protected virtual void DrawSubItem(Graphics g, ChatListSubItem subItem, ref Rectangle rectSubItem, SolidBrush sb)
- {
- if (subItem.Equals(this.selectSubItem))
- {
- rectSubItem.Height = 53;
- sb.Color = this.subItemSelectColor;
- g.FillRectangle(sb, rectSubItem);
- this.DrawHeadImage(g, subItem, rectSubItem);
- this.DrawLargeSubItem(g, subItem, rectSubItem);
- subItem.Bounds = new Rectangle(rectSubItem.Location, rectSubItem.Size);
- return;
- }
- if (subItem.Equals(this.m_mouseOnSubItem))
- {
- sb.Color = this.subItemMouseOnColor;
- }
- else
- {
- sb.Color = this.subItemColor;
- }
- g.FillRectangle(sb, rectSubItem);
- this.DrawHeadImage(g, subItem, rectSubItem);
- if (this.iconSizeMode == ChatListItemIcon.Large)
- {
- this.DrawLargeSubItem(g, subItem, rectSubItem);
- }
- else
- {
- this.DrawSmallSubItem(g, subItem, rectSubItem);
- }
- subItem.Bounds = new Rectangle(rectSubItem.Location, rectSubItem.Size);
- }
- /// <summary>
- /// 绘制图片
- /// </summary>
- /// <param name="g"></param>
- /// <param name="subItem"></param>
- /// <param name="rectSubItem"></param>
- protected virtual void DrawHeadImage(Graphics g, ChatListSubItem subItem, Rectangle rectSubItem)
- {
- if (subItem.IsTwinkle && subItem.IsTwinkleHide)
- {
- return;
- }
- int imageHeight = (rectSubItem.Height == 53) ? 40 : 20;
- subItem.HeadRect = new Rectangle(5, rectSubItem.Top + (rectSubItem.Height - imageHeight) / 2, imageHeight, imageHeight);
- if (subItem.HeadImage == null)
- {
- subItem.HeadImage = LYFZ.ComponentLibrary.Properties.Resources.tools_256px;
- }
- if (subItem.Status == ChatListSubItem.UserStatus.OffLine)
- {
- //subItem.HeadImage = GetGrayImage(subItem.HeadImage);
- //g.DrawImage(subItem.GetDarkImage(), subItem.HeadRect);//获取默认图标 离线图标
- // g.DrawImage(LYFZ.ComponentLibrary.Properties.Resources.Prohibit, new Rectangle(subItem.HeadRect.Right - 16, subItem.HeadRect.Bottom - 16, 16, 16));
- g.DrawImage(subItem.HeadImage, subItem.HeadRect);//获取默认图标
- }
- else
- {
- g.DrawImage(subItem.HeadImage, subItem.HeadRect);
-
- //if (subItem.Status == ChatListSubItem.UserStatus.QMe)
- //{
- // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
- //}
- //if (subItem.Status == ChatListSubItem.UserStatus.Away)
- //{
- // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
- //}
- //if (subItem.Status == ChatListSubItem.UserStatus.Busy)
- //{
- // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
- //}
- //if (subItem.Status == ChatListSubItem.UserStatus.DontDisturb)
- //{
- // g.DrawImage(subItem.HeadImage, new Rectangle(subItem.HeadRect.Right - 11, subItem.HeadRect.Bottom - 11, 11, 11));
- //}
- }
- if (subItem.Status != ChatListSubItem.UserStatus.OffLine)
- {
- //当选中当前子项目时显示的图标
- if (subItem.Equals(this.selectSubItem))
- {
- g.DrawImage(subItem.HeadImage, subItem.HeadRect.X - 2, subItem.HeadRect.Y - 2, 44, 44);
- return;
- }
- }
- Pen pen = new Pen(Color.FromArgb(200, 255, 255, 255));
- g.DrawRectangle(pen, subItem.HeadRect);
- }
- protected virtual void DrawLargeSubItem(Graphics g, ChatListSubItem subItem, Rectangle rectSubItem)
- {
- rectSubItem.Height = 53;
- string strDraw = subItem.DisplayName;
- Size szFont = TextRenderer.MeasureText(strDraw, this.Font);
- //TextRenderer.MeasureText(subItem.NicName, this.Font);
- StringFormat Sf = new StringFormat(StringFormatFlags.NoWrap);
- Sf.Trimming = StringTrimming.Word;
- Rectangle Rc = new Rectangle(new Point(rectSubItem.Height, rectSubItem.Top + 8), new Size(base.Width - 9 - rectSubItem.Height, szFont.Height));
- if (!IsDescription)
- {
- Rc.Location = new Point(Rc.Location.X, Rc.Location.Y+9);
- }
- // Rectangle NickNameRc = new Rectangle(new Point(rectSubItem.Height + szFont.Width, rectSubItem.Top + 8), new Size(base.Width - 9 - rectSubItem.Height - szFont.Width, szFont.Height));
- if (szFont.Width > 0)
- {
- g.DrawString(strDraw, this.Font, Brushes.Black, Rc, Sf);
- //g.DrawString("(" + subItem.NicName + ")", this.Font, Brushes.Gray, NickNameRc, Sf);
- }
- else
- {
- //Rectangle nkNameRc = new Rectangle(new Point(rectSubItem.Height, rectSubItem.Top + 8), new Size(base.Width - 9 - rectSubItem.Height, szFont.Height));
- //g.DrawString(subItem.NicName, this.Font, Brushes.Black, nkNameRc, Sf);
- g.DrawString(subItem.NicName, this.Font, Brushes.Black, Rc, Sf);
- }
- if (IsDescription)
- {
- Size MsgFont = TextRenderer.MeasureText(subItem.PersonalMsg, this.Font);
- Rectangle MsgRc = new Rectangle(new Point(rectSubItem.Height, rectSubItem.Top + 11 + this.Font.Height), new Size(base.Width - rectSubItem.Height, MsgFont.Height));
- Font PersonalMsgFont = new Font(this.Font.FontFamily, 8);
- g.DrawString(subItem.PersonalMsg, PersonalMsgFont, Brushes.Gray, MsgRc, Sf);
- }
- }
- protected virtual void DrawSmallSubItem(Graphics g, ChatListSubItem subItem, Rectangle rectSubItem)
- {
- rectSubItem.Height = 27;
- StringFormat sf = new StringFormat();
- sf.LineAlignment = StringAlignment.Center;
- sf.FormatFlags = StringFormatFlags.NoWrap;
- string strDraw = subItem.DisplayName;
- if (string.IsNullOrEmpty(strDraw))
- {
- strDraw = subItem.NicName;
- }
- Size szFont = TextRenderer.MeasureText(strDraw, this.Font);
- sf.SetTabStops(0f, new float[]
- {
- (float)rectSubItem.Height
- });
- g.DrawString("\t" + strDraw, this.Font, Brushes.Black, rectSubItem, sf);
- sf.SetTabStops(0f, new float[]
- {
- (float)(rectSubItem.Height + 5 + szFont.Width)
- });
- g.DrawString("\t" + subItem.PersonalMsg, this.Font, Brushes.Gray, rectSubItem, sf);
- }
- private void ClearItemMouseOn()
- {
- if (this.m_mouseOnItem != null)
- {
- int z = 0;
- if (this.chatVScroll.ShouldBeDraw)
- {
- z = 9;
- }
- 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));
- this.m_mouseOnItem = null;
- }
- }
- private void ClearSubItemMouseOn()
- {
- if (this.m_mouseOnSubItem != null)
- {
- int z = 0;
- if (this.chatVScroll.ShouldBeDraw)
- {
- z = 9;
- }
- 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));
- this.m_mouseOnSubItem = null;
- }
- }
- public ChatListSubItem[] GetSubItemsById(int userId)
- {
- List<ChatListSubItem> subItems = new List<ChatListSubItem>();
- int i = 0;
- int lenI = this.items.Count;
- while (i < lenI)
- {
- int j = 0;
- int lenJ = this.items[i].SubItems.Count;
- while (j < lenJ)
- {
- if (userId == this.items[i].SubItems[j].ID)
- {
- subItems.Add(this.items[i].SubItems[j]);
- }
- j++;
- }
- i++;
- }
- return subItems.ToArray();
- }
- public ChatListSubItem[] GetSubItemsByNicName(string nicName)
- {
- List<ChatListSubItem> subItems = new List<ChatListSubItem>();
- int i = 0;
- int lenI = this.items.Count;
- while (i < lenI)
- {
- int j = 0;
- int lenJ = this.items[i].SubItems.Count;
- while (j < lenJ)
- {
- if (nicName == this.items[i].SubItems[j].NicName)
- {
- subItems.Add(this.items[i].SubItems[j]);
- }
- j++;
- }
- i++;
- }
- return subItems.ToArray();
- }
- public ChatListSubItem[] GetSubItemsByDisplayName(string displayName)
- {
- List<ChatListSubItem> subItems = new List<ChatListSubItem>();
- int i = 0;
- int lenI = this.items.Count;
- while (i < lenI)
- {
- int j = 0;
- int lenJ = this.items[i].SubItems.Count;
- while (j < lenJ)
- {
- if (displayName == this.items[i].SubItems[j].DisplayName)
- {
- subItems.Add(this.items[i].SubItems[j]);
- }
- j++;
- }
- i++;
- }
- return subItems.ToArray();
- }
- public ChatListSubItem[] GetSubItemsByIp(string Ip)
- {
- List<ChatListSubItem> subItems = new List<ChatListSubItem>();
- int i = 0;
- int lenI = this.items.Count;
- while (i < lenI)
- {
- int j = 0;
- int lenJ = this.items[i].SubItems.Count;
- while (j < lenJ)
- {
- if (Ip == this.items[i].SubItems[j].IpAddress)
- {
- subItems.Add(this.items[i].SubItems[j]);
- }
- j++;
- }
- i++;
- }
- return subItems.ToArray();
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing && this.components != null)
- {
- this.components.Dispose();
- }
- base.Dispose(disposing);
- }
- private void InitializeComponent()
- {
- base.SuspendLayout();
- base.ResumeLayout(false);
- }
- }
- }
|