/// <summary> /// Handles the item drawing of a selected item. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param> /// <param name="hover">Determines whether the cursor is currently hovering over the item.</param> protected override void DrawItemSelected(DrawItemEventArgs e, bool hover) { e.Graphics.FillRectangle( GdiCache.GetBrushFromColor(ThemeManager.CurrentApplicationTheme.ColorPalette.SelectionBackgroundFocused) , 0 , e.Bounds.Top , e.Bounds.Width , e.Bounds.Height); }
private void DrawNodeFocusedHighlight(DrawTreeNodeEventArgs e, Rectangle bounds) { if ((e.State & TreeNodeStates.Selected) != TreeNodeStates.Selected) { return; } Brush nodeBackgroundBrush = (e.State & TreeNodeStates.Focused) == TreeNodeStates.Focused ? GdiCache.GetBrushFromColor(ThemeManager.CurrentApplicationTheme.ColorPalette.SelectionBackgroundFocused) : GdiCache.GetBrushFromColor(ThemeManager.CurrentApplicationTheme.ColorPalette.SelectionBackground); e.Graphics.FillRectangle(nodeBackgroundBrush, bounds); }
/// <summary> /// Handles the drawing of the item text. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param> protected override void DrawItemText(DrawItemEventArgs e) { e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; e.Graphics.DrawString( Items[e.Index].ToString() , Font , GdiCache.GetBrushFromColor((e.State & DrawItemState.Selected) == DrawItemState.Selected ? Focused ? ThemeManager.CurrentApplicationTheme.ColorPalette.SelectionForegroundFocused : ThemeManager.CurrentApplicationTheme.ColorPalette.SelectionForeground : ThemeManager.CurrentApplicationTheme.ColorPalette.ContentForeground) , new Rectangle(2, e.Bounds.Top + 2, e.Bounds.Width - 4, e.Bounds.Height - 4) , mStringFormat); }
private void DrawNodeFocusedHighlight(DrawTreeNodeEventArgs e, Rectangle bounds) { if ((e.State & TreeNodeStates.Selected) != TreeNodeStates.Selected) { return; } int scrollWidth = tvLoggerTree.IsVerticalScrollbarvisible() ? SystemInformation.VerticalScrollBarWidth : 0; Brush nodeBackgroundBrush = (e.State & TreeNodeStates.Focused) == TreeNodeStates.Focused ? GdiCache.GetBrushFromColor(ThemeManager.CurrentApplicationTheme.ColorPalette.SelectionBackgroundFocused) : GdiCache.GetBrushFromColor(ThemeManager.CurrentApplicationTheme.ColorPalette.SelectionBackground); e.Graphics.FillRectangle(nodeBackgroundBrush, bounds); }
/// <summary> /// Handles the OnPaint event. /// </summary> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientRectangle.Width > 0 && ClientRectangle.Height > 0) { var spaceLeft = VerticalScrollBar.Visible ? SystemInformation.VerticalScrollBarWidth : 0; var spaceBottom = HorizontalScrollBar.Visible ? SystemInformation.HorizontalScrollBarHeight : 0; e.Graphics.FillRectangle(GdiCache.GetBrushFromColor(Theme.ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground), new Rectangle( ClientRectangle.Width - spaceLeft, ClientRectangle.Height - spaceBottom, SystemInformation.VerticalScrollBarWidth, SystemInformation.HorizontalScrollBarHeight)); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.ListBox.DrawItem"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param> protected override void OnDrawItem(DrawItemEventArgs e) { if (Items.Count == 0 || e.Index > Items.Count) { return; } e.Graphics.FillRectangle(GdiCache.GetBrushFromColor(ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground), e.Bounds); if (Items[e.Index] is Seperator) { DrawSeperator(e); return; } bool isSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected; bool isHover = mMouseIndex != -1 && e.Index == mMouseIndex; if (isSelected) { DrawItemSelected(e, isHover); if (Focused && ShowFocusCues) { ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle( e.Bounds.X + 1 , e.Bounds.Y + 1 , e.Bounds.Width - 2 , e.Bounds.Height - 2)); } } if (isHover) { DrawItemHighlighted(e, isSelected); } DrawItemText(e); }
/// <summary> /// Handles the DrawNode event oft the logger <see cref="TreeView"/>. /// </summary> private void TvLoggerTreeDrawNode(object sender, DrawTreeNodeEventArgs e) { e.DrawDefault = false; if (e.Node.Bounds.IsEmpty) { return; } Rectangle bounds = new Rectangle( 0 , e.Node.Bounds.Y , Width - 1 , e.Node.Bounds.Height - 1); e.Graphics.FillRectangle( GdiCache.GetBrushFromColor(ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground) , bounds); DrawNodeFocusedHighlight(e, bounds); DrawPlusMinus(e); DrawNodeText(e); }
/// <summary> /// Handles the CellPainting event of the <see cref="DataGridView"/>. /// </summary> private void DtgLogMessagesCellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex >= mFilteredLogMessages.Count || e.RowIndex < 0) { return; } if ((e.State & DataGridViewElementStates.Visible) == DataGridViewElementStates.None) { return; } Color foreColor = SystemColors.WindowText; Color backColor = SystemColors.Window; Brush backgroundBrush = null; if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected) { foreColor = SystemColors.HighlightText; backColor = SystemColors.MenuHighlight; backgroundBrush = GdiCache.GetBrushFromColor(backColor); } else { switch (mFilteredLogMessages[e.RowIndex].Level) { case LogLevel.Trace: foreColor = Settings.Default.ForegroundColorTrace; backColor = Settings.Default.BackgroundColorTrace; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Debug: foreColor = Settings.Default.ForegroundColorDebug; backColor = Settings.Default.BackgroundColorDebug; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Info: foreColor = Settings.Default.ForegroundColorInfo; backColor = Settings.Default.BackgroundColorInfo; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Warning: foreColor = Settings.Default.ForegroundColorWarning; backColor = Settings.Default.BackgroundColorWarning; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Error: foreColor = Settings.Default.ForegroundColorError; backColor = Settings.Default.BackgroundColorError; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Fatal: foreColor = Settings.Default.ForegroundColorFatal; backColor = Settings.Default.BackgroundColorFatal; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; } } if (backgroundBrush != null) { e.Graphics.FillRectangle( backgroundBrush , e.CellBounds); if (e.ColumnIndex == 0) { // the first column may be an image. e.PaintContent(e.CellBounds); } else { TextRenderer.DrawText( e.Graphics , e.Value.ToString() , dtgLogMessages.DefaultCellStyle.Font , e.CellBounds , foreColor , backColor , TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter); } e.Graphics.DrawRectangle( Settings.Default.LogWindowDrawGrid ? GdiCache.GetPenFromColor(dtgLogMessages.GridColor) : GdiCache.GetPenFromColor(backColor) , e.CellBounds); e.Handled = true; } }
/// <summary> /// Handles the CellPainting event of the <see cref="DataGridView"/>. /// </summary> private void DtgLogMessagesCellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex >= mFilteredLogMessages.Count || e.RowIndex < 0) { return; } if ((e.State & DataGridViewElementStates.Visible) == DataGridViewElementStates.None) { return; } Color foreColor = SystemColors.WindowText; Color backColor = SystemColors.Window; Brush backgroundBrush = null; FontStyle fontStyle = FontStyle.Regular; switch (mFilteredLogMessages[e.RowIndex].Level) { case LogLevel.Trace: foreColor = Settings.Default.ForegroundColorTrace; backColor = Settings.Default.BackgroundColorTrace; fontStyle = Settings.Default.FontStyleTrace; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Debug: foreColor = Settings.Default.ForegroundColorDebug; backColor = Settings.Default.BackgroundColorDebug; fontStyle = Settings.Default.FontStyleDebug; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Info: foreColor = Settings.Default.ForegroundColorInfo; backColor = Settings.Default.BackgroundColorInfo; fontStyle = Settings.Default.FontStyleInfo; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Warning: foreColor = Settings.Default.ForegroundColorWarning; backColor = Settings.Default.BackgroundColorWarning; fontStyle = Settings.Default.FontStyleWarning; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Error: foreColor = Settings.Default.ForegroundColorError; backColor = Settings.Default.BackgroundColorError; fontStyle = Settings.Default.FontStyleError; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; case LogLevel.Fatal: foreColor = Settings.Default.ForegroundColorFatal; backColor = Settings.Default.BackgroundColorFatal; fontStyle = Settings.Default.FontStyleFatal; backgroundBrush = GdiCache.GetBrushFromColor(backColor); break; } if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected) { if (Settings.Default.UseInvertedColorForSelection) { // Invert the colors for selected items. Color tmpForecolor = foreColor; foreColor = backColor; backColor = tmpForecolor; backgroundBrush = GdiCache.GetBrushFromColor(tmpForecolor); } else { // Use the default system colors for selected items. foreColor = SystemColors.HighlightText; backColor = SystemColors.MenuHighlight; backgroundBrush = GdiCache.GetBrushFromColor(backColor); } } if (backgroundBrush != null) { e.Graphics.FillRectangle( backgroundBrush , e.CellBounds); if (e.ColumnIndex == 0) { // the first column may be an image. e.PaintContent(e.CellBounds); } else { Font logFont = FontCache.GetFontFromIdentifier( e.CellStyle.Font.Name , e.CellStyle.Font.Size , fontStyle); TextRenderer.DrawText( e.Graphics , e.Value?.ToString() ?? string.Empty , logFont , e.CellBounds , foreColor , backColor , TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter); } e.Graphics.DrawRectangle( Settings.Default.LogWindowDrawGrid ? GdiCache.GetPenFromColor(dtgLogMessages.GridColor) : GdiCache.GetPenFromColor(backColor) , e.CellBounds); e.Handled = true; } }