Example #1
0
        private void lbOnline_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (lbOnline.Items.Count > 0 && e.Index != -1)
            {
                ClientUserAccount account = lbOnline.Items[e.Index] as ClientUserAccount;

                DrawingHelper.enableSmooth(e.Graphics, false);

                e.DrawBackground();

                if (account.unread > 0)
                {
                    e.Graphics.FillRectangle(Brushes.Orange, e.Bounds);
                }
                else if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    e = new DrawItemEventArgs(e.Graphics,
                                              e.Font,
                                              e.Bounds,
                                              e.Index,
                                              e.State ^ DrawItemState.Selected,
                                              e.ForeColor,
                                              Color.FromArgb(0, 180, 255));

                    e.DrawBackground();
                    e.DrawFocusRectangle();
                }

                Brush brush = account.banned ? new SolidBrush(Color.FromArgb(255, 50, 100)) : new SolidBrush(account.Online ? Color.FromArgb(150, 255, 50) : Color.FromArgb(50, 50, 50));

                e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Width - 5, e.Bounds.Y, 5, 50));

                Image img = ImageUtils.ResizeAndCrop(account.GetProfileImage(), 50, 50);

                DrawingHelper.enableSmooth(e.Graphics, true);

                e.Graphics.DrawImage(img, e.Bounds.X, e.Bounds.Y);

                if (account.unread > 0)
                {
                    DrawingHelper.enableSmooth(e.Graphics, false);
                    e.Graphics.FillRectangle(Brushes.Black, 0, e.Bounds.Y, 20, 20);
                    e.Graphics.FillRectangle(Brushes.Orange, 0, e.Bounds.Y, 19, 19);
                    DrawingHelper.enableSmooth(e.Graphics, true);

                    Font f = new Font(lbOnline.Font.FontFamily, 12f, FontStyle.Bold);

                    string text = $"{account.unread}";

                    SizeF size = e.Graphics.MeasureString(text, f, new Size(50, 50));

                    e.Graphics.DrawString(text, f, Brushes.Black, 9 - size.Width / 2f, e.Bounds.Y + (9 - size.Height / 2f) + 0.75f);
                }
                if (account.isTyping)
                {
                    Font f = new Font(lbOnline.Font.FontFamily, 21, FontStyle.Bold);

                    string text = "...";

                    SizeF s = e.Graphics.MeasureString(text, f, new Size(50, 50));

                    e.Graphics.FillRectangle(new SolidBrush(Color.Black), 10, e.Bounds.Y + 50 - 10, 50 - 20, 10);

                    e.Graphics.DrawString(text, f, Brushes.Turquoise, 25 - s.Width / 2f + 1, e.Bounds.Y + 25 - s.Height / 2f + 14);
                }

                int i = (int)e.Graphics.MeasureString(account.ToString(), lbOnline.Font, lbOnline.Width - 60).Height;
                e.Graphics.DrawString(account.ToString(), e.Font, new SolidBrush(Color.Black), new Rectangle(new Point(55, e.Bounds.Y + 25 - i / 2), new Size(e.Bounds.Width - 60, 50)));
            }
        }