/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data. </param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Pen drawPen = null; foreach (KeyValuePair <int, LogMessage> keyVal in mColoredLines) { if ((keyVal.Value.Level & (LogLevel)Settings.Default.ColorMapAnnotation) != keyVal.Value.Level) { continue; } switch (keyVal.Value.Level) { case LogLevel.Fatal: drawPen = ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground.Equals(Settings.Default.BackgroundColorFatal) ? GdiCache.GetPenFromColor(Settings.Default.ForegroundColorFatal) : GdiCache.GetPenFromColor(Settings.Default.BackgroundColorFatal); break; case LogLevel.Error: drawPen = ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground.Equals(Settings.Default.BackgroundColorError) ? GdiCache.GetPenFromColor(Settings.Default.ForegroundColorError) : GdiCache.GetPenFromColor(Settings.Default.BackgroundColorError); break; case LogLevel.Warning: drawPen = ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground.Equals(Settings.Default.BackgroundColorWarning) ? GdiCache.GetPenFromColor(Settings.Default.ForegroundColorWarning) : GdiCache.GetPenFromColor(Settings.Default.BackgroundColorWarning); break; case LogLevel.Info: drawPen = ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground.Equals(Settings.Default.BackgroundColorInfo) ? GdiCache.GetPenFromColor(Settings.Default.ForegroundColorInfo) : GdiCache.GetPenFromColor(Settings.Default.BackgroundColorInfo); break; case LogLevel.Debug: drawPen = ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground.Equals(Settings.Default.BackgroundColorDebug) ? GdiCache.GetPenFromColor(Settings.Default.ForegroundColorDebug) : GdiCache.GetPenFromColor(Settings.Default.BackgroundColorDebug); break; case LogLevel.Trace: drawPen = ThemeManager.CurrentApplicationTheme.ColorPalette.ContentBackground.Equals(Settings.Default.BackgroundColorTrace) ? GdiCache.GetPenFromColor(Settings.Default.ForegroundColorTrace) : GdiCache.GetPenFromColor(Settings.Default.BackgroundColorTrace); break; default: drawPen = null; break; } if (drawPen != null) { e.Graphics.DrawLine(drawPen, 0, keyVal.Key, Width, keyVal.Key); } } }
/// <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() , 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; } }