/// <summary> /// Draw the row. /// </summary> private void DrawSubItem(object sender, DrawListViewSubItemEventArgs args) { InboxConversation message = args.Item.Tag as InboxConversation; if (message != null) { DrawRectElements elements = ComputeDrawRectElements(args.Graphics, message, args.Bounds); Color textColor = UI.Forums.HeaderFooterColour; if (args.Item.Selected) { args.DrawFocusRectangle(elements.BoundaryRect); textColor = UI.Forums.SelectionTextColour; } // Draw the selection around the control. using (Pen edgePen = new Pen(args.Item.Selected ? UI.Forums.SelectionColour : BackColor)) { Color fillColour = args.Item.Selected ? UI.Forums.SelectionColour : UI.Forums.RootColour; using (Brush backBrush = new SolidBrush(fillColour)) { args.Graphics.FillRoundedRectangle(edgePen, backBrush, elements.BoundaryRect); } } using (Brush textBrush = new SolidBrush(textColor)) { // Draw read image Image readImage = ReadImageForMessage(message); args.Graphics.DrawImage(readImage, elements.ReadRect); // Draw author name args.Graphics.DrawString(message.Author, _font, textBrush, elements.AuthorRect); // Draw separator const string separatorChar = "•"; args.Graphics.DrawString(separatorChar, _font, textBrush, elements.Separator1Rect); // Draw date string dateString = (_showFullDate) ? message.Date.ToString("d MMM yyyy") + " " + message.Date.ToShortTimeString() : message.Date.FriendlyString(true); args.Graphics.DrawString(dateString, _font, textBrush, elements.DateRect); // Draw ID field string idString = (message.IsDraft) ? "Draft" : message.RemoteID.ToString(CultureInfo.InvariantCulture); args.Graphics.DrawString(idString, _font, textBrush, elements.IDRect); // Another separator args.Graphics.DrawString(separatorChar, _font, textBrush, elements.Separator2Rect); // Draw subject line string subjectLine = message.Subject; args.Graphics.DrawString(subjectLine, _font, textBrush, elements.SubjectRect, new StringFormat(StringFormatFlags.NoWrap)); } } }
/// <summary> /// Handle click on read icons on an item to change the read state of /// the conversation. /// </summary> private void OnMouseDown(object sender, MouseEventArgs mouseEventArgs) { ListViewItem item = inboxConversations.GetItemAt(mouseEventArgs.Location.X, mouseEventArgs.Location.Y); if (item != null) { if (item.Index >= 0 && item.Index < _conversations.Count) { InboxConversation message = _conversations[item.Index]; DrawRectElements elements = ComputeDrawRectElements(inboxConversations.CreateGraphics(), message, item.Bounds); if (elements.ReadRect.Contains(mouseEventArgs.Location)) { Action(ActionID.Read, message); } } } }
/// <summary> /// Compute the display rectangles for the various field elements of the given message /// </summary> private DrawRectElements ComputeDrawRectElements(Graphics graphics, InboxConversation message, Rectangle bounds) { DrawRectElements drawRectElements = new DrawRectElements(); Rectangle drawRect = bounds; drawRect.Inflate(-2, -2); // The rectangle for the selection and focus drawRectElements.BoundaryRect = drawRect; drawRect.Y = drawRect.Y + (drawRect.Height - _font.Height) / 2; drawRect.X += 4; drawRect.Width -= 4; // Compute Read image rectangle Image readImage = ReadImageForMessage(message); Rectangle imageRect = new Rectangle(drawRect.X, bounds.Y + (bounds.Height - readImage.Height) / 2, readImage.Width, readImage.Height); drawRectElements.ReadRect = imageRect; drawRect.X += readImage.Width + 4; drawRect.Width -= readImage.Width + 4; // Compute author name rectangle SizeF idSize = graphics.MeasureString(message.Author, _font); drawRectElements.AuthorRect = drawRect; drawRect.X += (int)idSize.Width + 4; drawRect.Width -= (int)idSize.Width + 4; // Compute first separator rectangle const string separatorChar = "•"; idSize = graphics.MeasureString(separatorChar, _font); drawRectElements.Separator1Rect = drawRect; drawRect.X += (int)idSize.Width + 4; drawRect.Width -= (int)idSize.Width + 4; // Compute date field rectangle string dateString = (_showFullDate) ? message.Date.ToString("d MMM yyyy") + " " + message.Date.ToShortTimeString() : message.Date.FriendlyString(true); idSize = graphics.MeasureString(dateString, _font); drawRectElements.DateRect = drawRect; drawRect.X += (int)idSize.Width + 4; drawRect.Width -= (int)idSize.Width + 4; // Compute ID field rectangle string idString = (message.IsDraft) ? "Draft" : message.RemoteID.ToString(CultureInfo.InvariantCulture); idSize = graphics.MeasureString(idString, _font); drawRectElements.IDRect = drawRect; drawRect.X += (int)idSize.Width + 4; drawRect.Width -= (int)idSize.Width + 4; // Compute second separator rectangle idSize = graphics.MeasureString(separatorChar, _font); drawRectElements.Separator2Rect = drawRect; // Compute subject line rectangle drawRect.X += (int)idSize.Width + 4; drawRect.Width -= (int)idSize.Width + 8; drawRectElements.SubjectRect = drawRect; return(drawRectElements); }