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 ((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)); DrawingHelper.enableSmooth(e.Graphics, true); Image img = ImageUtils.ResizeAndCrop(account.GetProfileImage(), 50, 50); e.Graphics.DrawImage(img, e.Bounds.X, e.Bounds.Y); 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))); } }
private void pbProfile_DragDrop(object sender, DragEventArgs e) { try { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); pbProfile.Image = ImageUtils.ResizeAndCrop(Image.FromFile(files[0]), 50, 50); pbProfile.Invalidate(); sendData(new ProfileUpdatePacket(_account.Nickname, pbProfile.Image)); } catch { } }
private void lbChat_DrawItem(object sender, DrawItemEventArgs e) { if (lbChat.Items.Count > 0 && e.Index != -1) { try { DrawingHelper.enableSmooth(e.Graphics, false); ChatNode node = lbChat.Items[e.Index] as ChatNode; 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(); } else { e.DrawBackground(); e.DrawFocusRectangle(); e.Graphics.FillRectangle(new SolidBrush(node.currentUser ? Color.FromArgb(192, 237, 252) : Color.FromArgb(240, 244, 248)), e.Bounds); } DrawingHelper.enableSmooth(e.Graphics, true); e.Graphics.DrawString(node.ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds); if (node.image != null) { Image cropped = ImageUtils.ResizeAndCrop(node.image, 150, 100); e.Graphics.TranslateTransform(0, lbChat.GetItemHeight(e.Index) - 100); e.Graphics.DrawImage(cropped, 0, e.Bounds.Y); } } catch { } } }