private void logListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { var item = e.Item.SubItems[e.ColumnIndex]; e.DrawBackground(); var text = item.Text; Color forecolor; if (text.StartsWith(@"ERROR") || text.StartsWith(@"FATAL")) { forecolor = Color.DarkRed; } else if (text.StartsWith(@"WARN")) { forecolor = Color.FromArgb(181, 166, 16); } else if (text.StartsWith(@"DEBUG")) { forecolor = Color.Black; } else { forecolor = Color.DarkBlue; } TextRenderer.DrawText(e.Graphics, item.Text, this.logListView.Font, e.Bounds, forecolor, TextFormatFlags.Left); e.DrawFocusRectangle(e.Bounds); }
private void UofListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { Rectangle subRect = e.Bounds; WorkingListViewItem item = ((WorkingListViewItem)e.Item); if (e.ColumnIndex == status.Index) { //High Light bool bHighLight = e.Item.Selected; if (bHighLight) { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Item.Bounds); } //Draw Focus if (e.Item.Focused) { e.DrawFocusRectangle(e.Item.Bounds); } } else if (e.ColumnIndex == name.Index) { //Draw Name DrawIcon(subRect, e.Graphics, item.FileIcon); } }
private void listViewLog_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { var item = e.Item.SubItems[e.ColumnIndex]; e.DrawBackground(); var text = item.Text; Color forecolor; if (text.StartsWith(@"ERROR", StringComparison.CurrentCultureIgnoreCase) || text.StartsWith(@"FATAL", StringComparison.CurrentCultureIgnoreCase)) { forecolor = _darkRedColor; } else if (text.StartsWith(@"WARN", StringComparison.CurrentCultureIgnoreCase)) { forecolor = Color.FromArgb(181, 166, 16); } else if (text.StartsWith(@"DEBUG")) { forecolor = Color.Black; } else { forecolor = Color.DarkBlue; } TextRenderer.DrawText(e.Graphics, item.Text, listViewLog.Font, e.Bounds, forecolor, TextFormatFlags.Left); e.DrawFocusRectangle(e.Bounds); }
/// <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)); } } }
private void lstContractList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { // Get the ListView item and the ServerStatus object. ListViewItem item = e.Item; Data server_status = item.Tag as Data; // Draw. switch (e.ColumnIndex) { case 0: // Draw the server's name. e.Graphics.DrawString(server_status.Contract, lstContractList.Font, Brushes.Black, e.Bounds); break; case 1: // Draw the server's logo. float scale = e.Bounds.Height / (float)server_status.Logo.Height; e.Graphics.ScaleTransform(scale, scale); e.Graphics.TranslateTransform( e.Bounds.Left, e.Bounds.Top + (e.Bounds.Height - server_status.Logo.Height * scale) / 2, System.Drawing.Drawing2D.MatrixOrder.Append); e.Graphics.DrawImage(server_status.Logo, 0, 0); break; case 2: // Draw the server's name. e.Graphics.DrawString(server_status.Status, lstContractList.Font, Brushes.Black, e.Bounds); break; } // Draw the focus rectangle if appropriate. e.Graphics.ResetTransform(); ListView lvw = e.Item.ListView; if (lvw.FullRowSelect) { e.DrawFocusRectangle(e.Item.Bounds); } else if (e.SubItem.Name == "Server") { e.DrawFocusRectangle(e.Bounds); } }
public void DrawFocusRectangle_NullItemFocused_ThrowsNullReferenceException() { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), null, new ListViewItem.ListViewSubItem(), 0, 0, new ColumnHeader(), ListViewItemStates.Focused); Assert.Throws <NullReferenceException>(() => e.DrawFocusRectangle(new Rectangle(1, 2, 3, 4))); } }
public void DrawFocusRectangle_NullItemNotFocused_Nop() { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), null, new ListViewItem.ListViewSubItem(), 0, 0, new ColumnHeader(), ListViewItemStates.Checked); e.DrawFocusRectangle(new Rectangle(1, 2, 3, 4)); } }
public void DrawListViewSubItemEventArgs_DrawFocusRectangle_HasGraphics_Success(Rectangle bounds, ListViewItem item, ListViewItem.ListViewSubItem subItem, int itemIndex, ColumnHeader header, ListViewItemStates itemState) { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var e = new DrawListViewSubItemEventArgs(graphics, bounds, item, subItem, itemIndex, 0, header, itemState); e.DrawFocusRectangle(new Rectangle(1, 2, 3, 4)); } }
public void DrawFocusRectangle_HasGraphics_Success(ListViewItemStates itemState) { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), 0, 0, new ColumnHeader(), itemState); e.DrawFocusRectangle(new Rectangle(1, 2, 3, 4)); } }
private void blockIDListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { if ((e.ItemState & ListViewItemStates.Selected) != 0) { e.DrawFocusRectangle(e.Bounds); } //e.DrawBackground(); e.DrawText(); }
private void listView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { Brush brush; Color backColor; Color foreColor; if (e.Item.Selected) { if (listView.Focused) { brush = SystemBrushes.Highlight; backColor = SystemColors.Highlight; foreColor = SystemColors.HighlightText; } else { // We use the same colors here as TreeViewMS does for // drawing unfocused selected rows. brush = Brushes.LightGray; backColor = Color.LightGray; foreColor = SystemColors.WindowText; } } else { brush = SystemBrushes.Window; backColor = SystemColors.Window; foreColor = SystemColors.WindowText; } if (e.ColumnIndex == 0) { // Erase the entire background when drawing the first sub-item e.Graphics.FillRectangle(brush, e.Item.Bounds); } if (e.ColumnIndex == colHdrDisplayText.Index) { var findResult = (FindResult)e.Item.Tag; var textRendererHelper = new TextRendererHelper { ForeColor = foreColor, BackColor = backColor, Font = e.Item.Font, HighlightFont = new Font(e.Item.Font, FontStyle.Bold), }; textRendererHelper.DrawHighlightedText(e.Graphics, e.SubItem.Bounds, findResult.FindMatch); } else { e.SubItem.ForeColor = foreColor; e.DrawText(); } if (e.ColumnIndex == 0) { e.DrawFocusRectangle(e.Bounds); } }
private void TailListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { if (e.Item.Selected) { e.SubItem.BackColor = SystemColors.Highlight; e.SubItem.ForeColor = SystemColors.HighlightText; } // Draw the standard header background. e.DrawBackground(); e.DrawFocusRectangle(e.Bounds); System.Windows.Forms.TextRenderer.DrawText(e.Graphics, e.SubItem.Text, Font, e.Bounds, e.SubItem.ForeColor, TFFlags); }
private void OnListViewDrawSubItem(object sender, DrawListViewSubItemEventArgs e) { var node = e.Item.Tag as TreeListViewNode; if ((node != null) && (e.ColumnIndex == 0)) { var draw_offset = GetNodeDrawOffset(node); var draw_icon = GetNodeIcon(node); var rect_base = e.Bounds; var rect_item = new Rectangle(rect_base.Left + draw_offset, 0, draw_offset + rect_base.Width, rect_base.Height); if (fore_color_cache_ != e.Item.ForeColor) { fore_color_cache_ = e.Item.ForeColor; fore_brush_cache_?.Dispose(); fore_brush_cache_ = new SolidBrush(fore_color_cache_); } // e.DrawBackground(); if (draw_icon != null) { e.Graphics.DrawImage( draw_icon, new Rectangle( draw_offset, e.Bounds.Top + (e.Bounds.Height - draw_icon.Height) / 2, draw_icon.Width, draw_icon.Height)); } draw_offset += GetNodeLevelOffset(); e.Graphics.DrawString( node.Text, e.Item.Font, fore_brush_cache_, new Rectangle(draw_offset, e.Bounds.Top, e.Bounds.Width - draw_offset, e.Bounds.Height), node_text_sformat); e.DrawFocusRectangle(e.Bounds); } else { e.DrawDefault = true; } }
private void lvCamtasiaInfo_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawBackground(); e.DrawText(); e.DrawFocusRectangle(e.Bounds); for (int i = 0; i < lvCamtasiaInfo.Items.Count; i++) { for (int j = 0; j < 9; j++) { if (lvCamtasiaInfo.Items[i].SubItems[8].Text == "待入库") { lvCamtasiaInfo.Items[i].SubItems[j].BackColor = Color.DarkGray; lvCamtasiaInfo.Items[i].SubItems[j].ForeColor = Color.Red; } } } }
void amuleDownloadStatusList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { if ((e.ColumnIndex == m_column_index[(int)DOWNLOAD_CTRL_COL_ID.COL_STATUS_ID]) && m_settings.StatusVisible) { // status is colored bar Rectangle r = e.Bounds; DownloadQueueItem it = e.Item.Tag as DownloadQueueItem; DrawStatusBar(it, e.Graphics, r); e.DrawDefault = false; } else { e.DrawBackground(); } e.DrawText(); if (e.Item.Selected) { e.DrawFocusRectangle(e.Bounds); } }
private void m_List_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawBackground(); e.DrawText(); if ((e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected) { e.DrawFocusRectangle(e.Item.Bounds); } if (e.ItemIndex > 0) { ListViewItem prevItem = m_List.Items[e.ItemIndex - 1]; if (prevItem != null) { if (((LogRowData)prevItem.Tag).CycleIndex != ((LogRowData)e.Item.Tag).CycleIndex) { e.Graphics.DrawLine(Pens.Black, e.SubItem.Bounds.Left, e.SubItem.Bounds.Top - 1, e.SubItem.Bounds.Right, e.SubItem.Bounds.Top - 1); } } } }
private void listViewarminman2_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawBackground(); //now we can use the backcolor to fill the item. e.DrawText(); e.DrawFocusRectangle(e.Bounds); }
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { // Get the ListView item and the ServerStatus object. ListViewItem item = e.Item; ListView lvw = e.Item.ListView; Image logo = null; //Ausgabeformat //StringFormat string_format = new StringFormat(); //string_format.Trimming = StringTrimming.EllipsisWord; //string_format.FormatFlags |= StringFormatFlags.NoWrap; //string_format.LineAlignment = StringAlignment.Center; //Zeichen Font //Font myFont = new Font(lvw.Font, FontStyle.Regular); Boolean selected = !((e.ItemState & ListViewItemStates.Selected) == 0); if ((item).ImageIndex >= 0) { logo = channelImageList.Images[(item).ImageIndex]; } // Draw. switch (e.ColumnIndex) { case 0: ImageAttributes imageAttributes = new ImageAttributes(); float[][] colorMatrixElements = { new float[] { 1, 0, 0, 0, 0 }, // red scaling factor of 2 new float[] { 0, 1, 0, 0, 0 }, // green scaling factor of 1 new float[] { 0, 0, 2, 0, 0 }, // blue scaling factor of 1 new float[] { 0, 0, 0, 1, 0 }, // alpha scaling factor of 1 new float[] { .2f, .2f, .2f, 0, 1 } }; // three translations of 0.2 ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); // Draw logo. if (logo != null) { float scale = e.Bounds.Height / (float)logo.Height; e.Graphics.ScaleTransform(scale, scale); e.Graphics.TranslateTransform(e.Bounds.Left, e.Bounds.Top + (e.Bounds.Height - logo.Height * scale) / 2, System.Drawing.Drawing2D.MatrixOrder.Append); if (selected) { //e.Graphics.DrawImage(logo, 0, 0); //e.Graphics.DrawImage(logo, new Rectangle(0, 0, logo.Width, logo.Height), 0, 0, logo.Width, logo.Height, GraphicsUnit.Pixel, imageAttributes); Bitmap logo2 = (Bitmap)logo.Clone(); Color c; for (int i = 0; i < logo2.Width; i++) { for (int j = 0; j < logo2.Height; j++) { c = logo2.GetPixel(i, j); logo2.SetPixel(i, j, Color.FromArgb(255 - c.R, 255 - c.G, 255 - c.B)); } } //Hintergrund blau zeichnen //DrawBackGround(e); //invertiertes Logo zeichnen e.Graphics.DrawImage(logo2, 0, 0); } else { e.Graphics.DrawImage(logo, 0, 0); } } break; case 1: // Draw the Channel Name DrawCell(item.SubItems[1].Text, selected, e); break; case 2: // Draw the Programm Name DrawCell(item.SubItems[2].Text, selected, e); break; case 3: // Draw Start/End Time DrawCell(item.SubItems[3].Text, selected, e); break; } // Draw the focus rectangle if appropriate. e.Graphics.ResetTransform(); if (lvw.FullRowSelect) { e.DrawFocusRectangle(e.Item.Bounds); } }
public void DrawFocusRectangle_NullGraphicsNotFocused_Nop() { var e = new DrawListViewSubItemEventArgs(null, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), 0, 0, new ColumnHeader(), ListViewItemStates.Checked); e.DrawFocusRectangle(new Rectangle(1, 2, 3, 4)); }
public void DrawFocusRectangle_NullGraphicsFocused_ThrowsArgumentNullException() { var e = new DrawListViewSubItemEventArgs(null, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), 0, 0, new ColumnHeader(), ListViewItemStates.Focused); Assert.Throws <ArgumentNullException>("graphics", () => e.DrawFocusRectangle(new Rectangle(1, 2, 3, 4))); }
private void listViewJournal_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { JournalListViewItem obj = e.Item as JournalListViewItem; //e.DrawBackground(); //e.DrawText(); switch (e.ColumnIndex) { case 0: // Date if (null == obj.obj) { e.Graphics.DrawString("-- Total -- ", e.Item.Font, new SolidBrush(e.Item.ForeColor), e.Bounds); } else { e.Graphics.DrawString(obj.obj.date.ToShortDateString() + " " + obj.obj.date.ToShortTimeString(), e.Item.Font, new SolidBrush(e.Item.ForeColor), e.Bounds, new StringFormat(StringFormatFlags.LineLimit)); } break; case 1: // ammount { StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Center; format.FormatFlags = StringFormatFlags.NoWrap; e.Graphics.DrawString(String.Format("{0:C}", Math.Abs(obj.obj.amount)), e.Item.Font, new SolidBrush(obj.obj.amount < 0 ? Color.Red : Color.Green), e.Bounds, format); } break; case 2: // type { e.Graphics.DrawString(String.Format("[{0:2}] {1}", obj.obj.refType.ToString(), AppData.ReferenceName[(int)obj.obj.refType]), e.Item.Font, new SolidBrush(e.Item.ForeColor), e.Bounds, new StringFormat(StringFormatFlags.LineLimit)); } break; case 3: // Name1 { e.Graphics.DrawString(String.Format("{0} [{1}]", obj.obj.ownerName1, obj.obj.ownerID1), e.Item.Font, new SolidBrush(e.Item.ForeColor), e.Bounds, new StringFormat(StringFormatFlags.LineLimit)); } break; case 4: // Name2 { e.Graphics.DrawString(String.Format("{0} [{1}]", obj.obj.ownerName2, obj.obj.ownerID2), e.Item.Font, new SolidBrush(e.Item.ForeColor), e.Bounds, new StringFormat(StringFormatFlags.LineLimit)); } break; case 5: // Arg1 { e.Graphics.DrawString(String.Format("{0} [{1}]", obj.obj.argName1, obj.obj.argID), e.Item.Font, new SolidBrush(e.Item.ForeColor), e.Bounds, new StringFormat(StringFormatFlags.LineLimit)); } break; case 6: // reason { e.Graphics.DrawString(obj.obj.reason, e.Item.Font, new SolidBrush(e.Item.ForeColor), e.Bounds, new StringFormat(StringFormatFlags.LineLimit)); } break; } e.DrawFocusRectangle(e.Bounds); }
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { // Get the ListView item and the ServerStatus object. ListViewItem item = e.Item; ListView lvw = e.Item.ListView; Image logo = null; //Ausgabeformat //StringFormat string_format = new StringFormat(); //string_format.Trimming = StringTrimming.EllipsisWord; //string_format.FormatFlags |= StringFormatFlags.NoWrap; //string_format.LineAlignment = StringAlignment.Center; //Zeichen Font //Font myFont = new Font(lvw.Font, FontStyle.Regular); Boolean selected = !((e.ItemState & ListViewItemStates.Selected) == 0); if ((item).ImageIndex >= 0) { logo = channelImageList.Images[(item).ImageIndex]; } // Draw. switch (e.ColumnIndex) { case 0: ImageAttributes imageAttributes = new ImageAttributes(); float[][] colorMatrixElements = { new float[] { 1, 0, 0, 0, 0 }, // red scaling factor of 2 new float[] { 0, 1, 0, 0, 0 }, // green scaling factor of 1 new float[] { 0, 0, 2, 0, 0 }, // blue scaling factor of 1 new float[] { 0, 0, 0, 1, 0 }, // alpha scaling factor of 1 new float[] { .2f, .2f, .2f, 0, 1 } }; // three translations of 0.2 ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); // Draw logo. if (logo != null) { float scale = e.Bounds.Height / (float)logo.Height; e.Graphics.ScaleTransform(scale, scale); e.Graphics.TranslateTransform(e.Bounds.Left, e.Bounds.Top + (e.Bounds.Height - logo.Height * scale) / 2, System.Drawing.Drawing2D.MatrixOrder.Append); if (selected) { //e.Graphics.DrawImage(logo, 0, 0); //e.Graphics.DrawImage(logo, new Rectangle(0, 0, logo.Width, logo.Height), 0, 0, logo.Width, logo.Height, GraphicsUnit.Pixel, imageAttributes); Bitmap logo2 = (Bitmap)logo.Clone(); Color c; for (int i = 0; i < logo2.Width; i++) { for (int j = 0; j < logo2.Height; j++) { c = logo2.GetPixel(i, j); logo2.SetPixel(i, j, Color.FromArgb(255 - c.R, 255 - c.G, 255 - c.B)); } } //Hintergrund blau zeichnen //DrawBackGround(e); //invertiertes Logo zeichnen e.Graphics.DrawImage(logo2, 0, 0); } else { e.Graphics.DrawImage(logo, 0, 0); } } break; case 1: // Draw the Channel Nr. DrawCell(item.SubItems[1].Text, selected, e, toolStripStatusLabel.Text.IndexOf(item.SubItems[2].Text) < 0); break; case 2: // Draw the Channel Name DrawCell(item.SubItems[2].Text, selected, e, toolStripStatusLabel.Text.IndexOf(item.SubItems[2].Text) < 0); break; case 3: // Draw Programm Name DrawCell(item.SubItems[3].Text, selected, e, toolStripStatusLabel.Text.IndexOf(item.SubItems[2].Text) < 0); break; case 4: // Draw Start/End Time int lProz = 0; if (item.SubItems[7].Text != "") { lProz = Convert.ToInt16(item.SubItems[7].Text); } if (lProz > 0) { Color lFarbe = Color.Gray; Rectangle rect = new Rectangle(e.Bounds.Left + 1, e.Bounds.Top + 1, e.Bounds.Width - 2, e.Bounds.Height - 3); SolidBrush lbr = new SolidBrush(lFarbe); //Rahmen zeichen Pen lPen = new Pen(lFarbe); e.Graphics.DrawRectangle(lPen, rect); //Füllung berechnen und zeichen int width = (e.Bounds.Width - 2) * lProz / 100; Rectangle rectProz = new Rectangle(e.Bounds.Left + 1, e.Bounds.Top + 1, width, e.Bounds.Height - 3); e.Graphics.FillRectangle(lbr, rectProz); } //Text ausgeben //Color pen_color = Color.FromArgb(255, 255 - lFarbe.R, 255 - lFarbe.G, 255 - lFarbe.B); Color pen_color = Color.Black; using (SolidBrush br = new SolidBrush(pen_color)) { StringFormat string_center = new StringFormat(); string_center.Alignment = StringAlignment.Center; string_center.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(item.SubItems[4].Text, lvw.Font, br, e.Bounds, string_center); } break; } // Draw the focus rectangle if appropriate. e.Graphics.ResetTransform(); if (lvw.FullRowSelect) { e.DrawFocusRectangle(e.Item.Bounds); } }