Пример #1
0
        public void DrawItem(CustomItemDrawData e)
        {
            e.DrawBackground();
            if (e.State == System.Windows.Forms.DrawItemState.Selected)
            {
                e.DrawFocusRectangle();
            }

            ChatUser user = e.Item as ChatUser;

            using (SolidBrush textBrush = new SolidBrush(e.ForeColor))
                using (StringFormat nameFormat = new StringFormat()
                {
                    Trimming = StringTrimming.EllipsisCharacter
                })
                    //using (StringFormat pingFormat = new StringFormat() { Trimming = StringTrimming.EllipsisCharacter, Alignment = StringAlignment.Center })
                    using (SolidBrush pingOutlineColor = new SolidBrush(Color.DarkRed))
                        using (Pen pingOutline = new Pen(pingOutlineColor))
                        {
                            UserStats stats        = user.Stats;
                            PointF    iconPosition = new PointF((float)e.Bounds.Left + 1.0f, (float)e.Bounds.Top + 1.0f);
                            e.Graphics.DrawImage(m_provider.GetImageFor(user.Flags, stats), iconPosition);

                            int userPing = user.Ping;
                            if (userPing < 0)
                            {
                                userPing = int.MaxValue;
                            }
                            int       pingWidth   = (int)Math.Min(28.0f * ((float)userPing / 600.0f), 28.0f);
                            Rectangle pingImgArea = new Rectangle(e.Bounds.Right - 33, e.Bounds.Y + (e.Bounds.Height - m_pingImg.Height) / 2,
                                                                  pingWidth, m_pingImg.Height);
                            e.Graphics.DrawImageUnscaledAndClipped(m_pingImg, pingImgArea);

                            //Rectangle pingOutlineBox = new Rectangle(pingImgArea.X, pingImgArea.Y, m_pingImg.Width - 1, m_pingImg.Height - 1);
                            //e.Graphics.DrawRectangle(pingOutline, pingOutlineBox);

                            //string userPingText = user.Ping.ToString(CultureInfo.CurrentCulture);
                            //e.Graphics.DrawString(userPingText, e.Font, textBrush, pingOutlineBox, pingFormat);

                            SizeF      nameSize = e.Graphics.MeasureString(user.Username, e.Font);
                            RectangleF nameArea = new RectangleF((float)e.Bounds.X + (float)m_provider.IconSize.Width + 1.0f + 4.0f,
                                                                 (float)e.Bounds.Y + (((float)e.Bounds.Height - nameSize.Height) / 2.0f),
                                                                 (float)e.Bounds.Width - 10.0f - 28.0f - (float)m_provider.IconSize.Width,
                                                                 (float)nameSize.Height);
                            e.Graphics.DrawString(user.Username, e.Font, textBrush, nameArea, nameFormat);
                        }
        }
Пример #2
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index < 0 || e.Index >= Items.Count)
            {
                base.OnDrawItem(e);
                return;
            }

            ICustomListBoxItemRenderer renderer = GetRenderer(e.Index);

            if (object.ReferenceEquals(null, renderer))
            {
                base.OnDrawItem(e);
            }
            else
            {
                CustomItemDrawData draw = new CustomItemDrawData(e, Items[e.Index]);
                renderer.DrawItem(draw);
            }
        }
Пример #3
0
        public void DrawItem(CustomItemDrawData e)
        {
            e.DrawBackground();
            if ((e.State & DrawItemState.Selected) == System.Windows.Forms.DrawItemState.Selected)
            {
                e.DrawFocusRectangle();
            }
            FriendUser friend = e.Item as FriendUser;

            Color textColor = e.ForeColor;

            if (friend.LocationType == FriendLocation.Offline)
            {
                if ((e.State & DrawItemState.Selected) == System.Windows.Forms.DrawItemState.Selected)
                {
                    textColor = Color.Black;
                }
                else
                {
                    textColor = Color.SlateGray;
                }
            }

            using (SolidBrush textBrush = new SolidBrush(textColor))
                using (StringFormat nameFormat = new StringFormat()
                {
                    Trimming = StringTrimming.EllipsisCharacter
                })
                {
                    PointF iconPosition = new PointF((float)e.Bounds.Location.X + 1.0f, (float)e.Bounds.Location.Y + 1.0f);
                    e.Graphics.DrawImage(m_provider.GetImageFor(friend.Product), (PointF)iconPosition);

                    SizeF      nameSize = e.Graphics.MeasureString(friend.AccountName, e.Font);
                    RectangleF nameArea = new RectangleF((float)e.Bounds.X + (float)m_provider.IconSize.Width + 1.0f + 4.0f,
                                                         (float)e.Bounds.Y + (((float)e.Bounds.Height - nameSize.Height) / 2.0f),
                                                         (float)e.Bounds.Width - (float)m_provider.IconSize.Width - 2.0f - 4.0f,
                                                         (float)nameSize.Height);
                    e.Graphics.DrawString(friend.AccountName, e.Font, textBrush, nameArea, nameFormat);
                }
        }