private void RenderSingleItem(Graphics g, ref FlowChatMessageContentItemModel item) { int avatarLeft; int msgLeft; int msgTextLeft; Color msgColor; StringFormat sf = new StringFormat(); sf.FormatFlags = StringFormatFlags.MeasureTrailingSpaces; float finalMsgTextWidth = g.MeasureString(item.MessageText, Font, 500).Width; float finalMsgRectWidth = finalMsgTextWidth + MSG_BETWEEN_TEXT_AND_RECT_WIDTH * 2; int tringleLeftUp; int tringleLeftMid; int tringleLeftDown; if (item.IsMe) { avatarLeft = Width - 30 - 34; msgLeft = Width - 74 - ((int)finalMsgRectWidth > MAX_MSG_RECT_WIDTH ? MAX_MSG_RECT_WIDTH : (int)finalMsgRectWidth); msgTextLeft = Width - 83 - ((int)finalMsgTextWidth > MAX_MSG_TEXT_WIDTH ? MAX_MSG_TEXT_WIDTH : (int)finalMsgTextWidth); msgColor = Color.FromArgb(151, 236, 119); tringleLeftUp = Width - 74; tringleLeftMid = Width - 69; tringleLeftDown = Width - 74; } else { avatarLeft = 30; msgLeft = 74; msgTextLeft = 83; msgColor = Color.White; tringleLeftUp = 74; tringleLeftMid = 69; tringleLeftDown = 74; } Rectangle avatarRect = new Rectangle(avatarLeft, view_y + 15, 34, 34); if (File.Exists(item.ImageUrl)) { g.DrawImage(new Bitmap(item.ImageUrl), avatarRect); } else { g.DrawImage(new Bitmap("./images/avatar-default.png"), avatarRect); } Point[] poins = new Point[3] { new Point(tringleLeftUp, view_y + 26), new Point(tringleLeftMid, view_y + 30), new Point(tringleLeftDown, view_y + 34) }; g.FillPolygon(new SolidBrush(msgColor), poins); Rectangle msgRect = new Rectangle(msgLeft, view_y + 14, (int)finalMsgRectWidth, 35); g.FillRectangle(new SolidBrush(msgColor), msgRect); Rectangle msgTextRect = new Rectangle(msgTextLeft, view_y + 24, (int)finalMsgTextWidth, 16); g.DrawString(item.MessageText, new Font(FontFamily.GenericMonospace, 10, FontStyle.Regular), Brushes.Black, msgTextRect); y += 50; }
private void PaintNewItem(FlowChatMessageContentItemModel item) { Graphics g = CreateGraphics(); CalculateViewY(); RenderSingleItem(g, ref item); }
public void AddNewMessage(FlowChatMessageContentItemModel item) { ChatItems.Add(item); PaintNewItem(item); }