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; /// /// 是否显示功能说明文字 /// [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); } /// /// 绘制图片 /// /// /// /// 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 subItems = new List(); 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 subItems = new List(); 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 subItems = new List(); 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 subItems = new List(); 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); } } }