protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { _brush?.Dispose(); _brush = null; } }
public void Dispose() { Path?.Dispose(); Pen?.Dispose(); EraseRegion?.Dispose(); Brush?.Dispose(); }
protected override void OnDrawItem(DrawItemEventArgs e) { var item_text = Items[e.Index].ToString(); var item_group = GetItemGroupInfo(e.Index); var item_font = e.Font; var item_fore_color = ForeColor; var item_back_color = BackColor; if (item_group.group != null) { if (item_group.group.Font != null) { item_font = item_group.group.Font; } if (item_group.group.ForeColor != Color.Transparent) { item_fore_color = item_group.group.ForeColor; } if (item_group.group.BackColor != Color.Transparent) { item_back_color = item_group.group.BackColor; } } /* キャッシュの色と異なる場合のみブラシ作成 */ if (fore_color_ != item_fore_color) { fore_color_ = item_fore_color; fore_brush_?.Dispose(); fore_brush_ = new SolidBrush(fore_color_); } if (back_color_ != item_back_color) { back_color_ = item_back_color; back_brush_?.Dispose(); back_brush_ = new SolidBrush(back_color_); } /* 指定の背景色で上書き */ if (item_back_color != Color.Transparent) { // e.Graphics.FillRectangle(back_brush_, e.Bounds); } /* 背景描画 */ e.DrawBackground(); /* テキスト描画 */ e.Graphics.DrawString(item_text, item_font, fore_brush_, e.Bounds); /* グループの境目を表示する */ if ((item_group.group != null) && ((item_group.index_rel + 1) >= item_group.group_item_count)) { e.Graphics.DrawLine(Pens.Gray, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1); } e.DrawFocusRectangle(); }
/// <summary> /// Update or create the brush used for drawing the background /// </summary> protected virtual void RecreateBackgroundBrush() { lock (this) { _backBrush?.Dispose(); _backBrush = new SolidBrush(BackColor); if (BackColor.A == 255) { return; } if (Parent != null) { using (var parentImage = new Bitmap(Parent.Width, Parent.Height)) { using (var parentGraphic = Graphics.FromImage(parentImage)) { var pe = new PaintEventArgs(parentGraphic, new Rectangle(new Point(0, 0), parentImage.Size)); InvokePaintBackground(Parent, pe); InvokePaint(Parent, pe); if (BackColor.A > 0) // Translucent { parentGraphic.FillRectangle(_backBrush, Bounds); } } _backBrush = new TextureBrush(parentImage); ((TextureBrush)_backBrush).TranslateTransform(-Bounds.X, -Bounds.Y); } } else { _backBrush = new SolidBrush(Color.FromArgb(255, BackColor)); } } }
private void Cleanup() { isRunning = false; renderThread?.Join(); tripleBuffer?.Dispose(); stringFormat?.Dispose(); fontCategoryNames?.Dispose(); fontTeamNames?.Dispose(); fontScores?.Dispose(); penGridLines?.Dispose(); brushTeamNames?.Dispose(); brushScores?.Dispose(); bitmapScores?.Dispose(); if (brushesFireworks != null) { foreach (Brush brush in brushesFireworks) { brush?.Dispose(); } } if (brushesCategories != null) { foreach (Brush brush in brushesCategories) { brush?.Dispose(); } } }
/// <summary> /// Dispose /// </summary> public void Dispose() { foreach (var textFormat in TextFormats.Values) { textFormat.Dispose(); } TextFormats.Clear(); Brush?.Dispose(); TextFormat?.Dispose(); TextFormat = null; Brush?.Dispose(); Brush = null; Target?.Dispose(); Target = null; NativeDeviceContext.Target = null; NativeDeviceContext?.Dispose(); NativeDeviceContext = null; NativeDevice?.Dispose(); NativeDevice = null; NativeFactory?.Dispose(); NativeFactory = null; NativeFactoryWrite?.Dispose(); NativeFactoryWrite = null; }
private void DrawText(MapGraphics g, bool drawShadow) { if (string.IsNullOrEmpty(Text)) { return; } RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f)); string text = Text; _ = Font; text = text.Replace("\\n", "\n"); StringFormat stringFormat = GetStringFormat(); TextRenderingHint textRenderingHint = g.TextRenderingHint; float num = DetermineAngle(); if (num % 90f != 0f) { g.TextRenderingHint = TextRenderingHint.AntiAlias; } Brush brush = null; brush = ((!drawShadow) ? new SolidBrush(TextColor) : g.GetShadowBrush()); try { if (num != 0f) { RectangleF layoutRectangle = DetermineTextRectangle(g, stringFormat); PointF point = new PointF(layoutRectangle.X + layoutRectangle.Width / 2f, layoutRectangle.Y + layoutRectangle.Height / 2f); Matrix transform = g.Transform; Matrix matrix = g.Transform.Clone(); matrix.RotateAt(num, point, MatrixOrder.Prepend); if (drawShadow) { matrix.Translate(TextShadowOffset, TextShadowOffset, MatrixOrder.Append); } g.Transform = matrix; StringFormat stringFormat2 = new StringFormat(); stringFormat2.Alignment = StringAlignment.Center; stringFormat2.LineAlignment = StringAlignment.Center; stringFormat2.Trimming = StringTrimming.EllipsisCharacter; layoutRectangle.Inflate(1000f, 1000f); g.DrawString(text, Font, brush, layoutRectangle, stringFormat2); g.Transform = transform; } else { if (drawShadow) { absoluteRectangle.X += TextShadowOffset; absoluteRectangle.Y += TextShadowOffset; } g.DrawString(text, Font, brush, absoluteRectangle, stringFormat); } } finally { brush?.Dispose(); } g.Graphics.TextRenderingHint = textRenderingHint; }
public static void Init() { if (!Directory.Exists(Program.RunLocal + "Video")) { Directory.CreateDirectory(Program.RunLocal + "Video"); } Config = ConfigUtils.VideoPic; back = ColorTranslator.FromHtml(Config.BackGround); name_color?.Dispose(); uid_color?.Dispose(); title_color?.Dispose(); info_color?.Dispose(); state_color?.Dispose(); name_font?.Dispose(); uid_font?.Dispose(); title_font?.Dispose(); info_font?.Dispose(); state_font?.Dispose(); name_color = new SolidBrush(ColorTranslator.FromHtml(Config.NameColor)); uid_color = new SolidBrush(ColorTranslator.FromHtml(Config.UidColor)); title_color = new SolidBrush(ColorTranslator.FromHtml(Config.TitleColor)); info_color = new SolidBrush(ColorTranslator.FromHtml(Config.InfoColor)); state_color = new SolidBrush(ColorTranslator.FromHtml(Config.StateColor)); name_font = new(Config.Font, Config.NameSize, FontStyle.Regular); uid_font = new(Config.Font, Config.UidSize, FontStyle.Regular); title_font = new(Config.Font, Config.TitleSize, FontStyle.Regular); info_font = new(Config.Font, Config.InfoSize, FontStyle.Regular); state_font = new(Config.Font, Config.StateSize, FontStyle.Regular); Qback = ColorTranslator.FromHtml(Config.QBack); Qpoint = ColorTranslator.FromHtml(Config.QPoint); }
protected override void Dispose(bool disposing) { if (disposing && !_isExternalBrush) { Brush?.Dispose(); } }
protected override void Dispose(bool disposing) { if (disposing) { whiteBrush?.Dispose(); } base.Dispose(disposing); }
public void Cleanup() { pen?.Dispose(); brush?.Dispose(); currentGraphics?.Dispose(); _penWidthBitmap?.Dispose(); _fillColorBitmap?.Dispose(); }
/// <summary> /// Disposes stuff. /// </summary> /// <param name="disposing">Indicats whether managed resources should be disposed.</param> protected override void Dispose(bool disposing) { _colors = null; _backBrush?.Dispose(); _foreBrush?.Dispose(); base.Dispose(disposing); }
public void Clear() { PlotColor = null; FillBrush?.Dispose(); FillBrush = null; FrameBrush?.Dispose(); FrameBrush = null; InsetBrush?.Dispose(); InsetBrush = null; }
/// <summary> /// Disposes the unmanaged memory objects and optionally disposes the managed memory objects. /// </summary> /// <param name="disposing">Indicates whether managed objects should be disposed.</param> protected override void Dispose(bool disposing) { if (disposing) { _backcolorBrush?.Dispose(); _controlBrush?.Dispose(); _backImageBrush?.Dispose(); Page?.Dispose(); } base.Dispose(disposing); }
/// <summary> /// Disposes the unmanaged memory objects and optionally disposes /// the managed memory objects. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { _backcolorBrush?.Dispose(); _controlBrush?.Dispose(); _backImageBrush?.Dispose(); _buffer?.Dispose(); if (disposing) { components?.Dispose(); } base.Dispose(disposing); }
public void Dispose() { TextOutlinePen?.Dispose(); TextBrush?.Dispose(); TextFont?.Dispose(); POIBrush?.Dispose(); POI2Brush?.Dispose(); AltPen?.Dispose(); TravelPen?.Dispose(); BoundsRegion?.Dispose(); Graphics?.Dispose(); }
public void Dispose() { _DGV.CellPainting -= DGV_CellPaintingRowNumbers_useSelectedBackColor; _DGV.CellPainting -= DGV_CellPaintingRowNumbers; _SF_RowNumbers.Dispose(); _BackBrushColumnHover?.Dispose(); _BackBrushColumnHoverPushed?.Dispose(); _SelBackBrush?.Dispose(); _SelBorderPen?.Dispose(); _SelTextBrush?.Dispose(); }
protected override void Dispose(bool disposing) { if (!disposed) { disposed = true; backBrush?.Dispose(); foreBrush?.Dispose(); progressBarBrush?.Dispose(); progressBarBorderPen?.Dispose(); if (disposing) { GC.SuppressFinalize(this); } } }
private void CustomDispose(bool disposing) { if (disposing) { backFillTop?.Dispose(); backFillBottom?.Dispose(); primaryFont?.Dispose(); primarySmallFont?.Dispose(); SmallSplitPen?.Dispose(); SplitPen?.Dispose(); FontBrush?.Dispose(); graphics?.Dispose(); } Dispose(disposing); }
public void Dispose() { Icon icon = _notifyIcon.Icon; _notifyIcon.Icon = null; icon?.Dispose(); _notifyIcon.Dispose(); _brush?.Dispose(); _darkBrush?.Dispose(); _pen.Dispose(); _graphics.Dispose(); _bitmap.Dispose(); _font.Dispose(); _smallFont.Dispose(); }
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; } }
internal override void Render(GaugeGraphics g) { if (Common == null || !base.Visible || GetScale() == null || double.IsNaN(StartValue) || double.IsNaN(EndValue)) { return; } Common.GaugeCore.TraceWrite("GaugePaint", SR.TraceStartRendering(Name)); g.StartHotRegion(this); LinearScale scale = GetScale(); Pen pen = null; Brush brush = null; GraphicsPath graphicsPath = null; try { graphicsPath = g.GetLinearRangePath(scale.GetPositionFromValue(StartValue), scale.GetPositionFromValue(EndValue), StartWidth, EndWidth, scale.Position, GetGauge().GetOrientation(), DistanceFromScale, Placement, scale.Width); if (graphicsPath == null || !g.Graphics.VisibleClipBounds.IntersectsWith(graphicsPath.GetBounds())) { g.EndHotRegion(); Common.GaugeCore.TraceWrite("GaugePaint", SR.TraceRenderingComplete(Name)); return; } brush = g.GetLinearRangeBrush(graphicsPath.GetBounds(), base.FillColor, base.FillHatchStyle, base.FillGradientType, base.FillGradientEndColor, GetGauge().GetOrientation(), GetScale().GetReversed(), StartValue, EndValue); pen = new Pen(base.BorderColor, base.BorderWidth); pen.DashStyle = g.GetPenStyle(base.BorderStyle); g.FillPath(brush, graphicsPath); if (base.BorderStyle != 0 && base.BorderWidth > 0) { g.DrawPath(pen, graphicsPath); } } catch (Exception) { graphicsPath?.Dispose(); pen?.Dispose(); brush?.Dispose(); throw; } Common.GaugeCore.HotRegionList.SetHotRegion(this, PointF.Empty, graphicsPath); g.EndHotRegion(); Common.GaugeCore.TraceWrite("GaugePaint", SR.TraceRenderingComplete(Name)); }
private void UpdateDrawBrush() { if (back_color_ == BackColor) { return; } back_color_ = BackColor; back_color_brush_?.Dispose(); back_color_brush_ = new SolidBrush(back_color_); back_color_s_brush_?.Dispose(); back_color_s_brush_ = new SolidBrush( Color.FromArgb( Math.Min(back_color_.A + 10, 255), Math.Min(back_color_.R + 10, 255), Math.Min(back_color_.G + 10, 255), Math.Min(back_color_.B + 10, 255))); }
private void UpdateDrawBrush(bool force = false) { if ((!force) && (back_color_ == BackColor)) { return; } back_color_ = BackColor; back_color_brush_?.Dispose(); back_color_brush_ = new SolidBrush(back_color_); back_color_s_brush_?.Dispose(); back_color_s_brush_ = new SolidBrush( Color.FromArgb( Math.Min(back_color_.A + 0, 255), Math.Min(back_color_.R + 15, 255), Math.Min(back_color_.G + 15, 255), Math.Min(back_color_.B + 15, 255))); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } borderDotPen?.Dispose(); borderPen?.Dispose(); infoFont?.Dispose(); magnifierBorderPen?.Dispose(); magnifierBorderPen?.Dispose(); magnifierCrosshairBrush?.Dispose(); textBackgroundBrush?.Dispose(); textFontBrush?.Dispose(); image?.Dispose(); backgroundBrush?.Dispose(); backgroundHighlightBrush?.Dispose(); base.Dispose(disposing); }
/// <summary> /// Creates and returns a copy of the brush in the new render target. /// Used for changing render targets. /// A brush belongs to a render target, so when you want to draw with same brush in another render target /// - you need to create a copy of the brush in the new render target. /// </summary> /// <param name="sourceBrush">The brush.</param> /// <param name="newRenderTarget">The new render target.</param> /// <returns></returns> protected internal Brush CopyBrushToRenderTarget(Brush sourceBrush, RenderTarget newRenderTarget) { if (sourceBrush == null || newRenderTarget == null) return null; Brush newBrush; if (sourceBrush is SolidColorBrush) { newBrush = newRenderTarget.CreateSolidColorBrush( ((SolidColorBrush)sourceBrush).Color, new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform)); sourceBrush.Dispose(); return newBrush; } if (sourceBrush is LinearGradientBrush) { var oldGSC = ((LinearGradientBrush)sourceBrush).GradientStops; var newGSC = newRenderTarget.CreateGradientStopCollection(oldGSC, oldGSC.ColorInterpolationGamma, oldGSC.ExtendMode); oldGSC.Dispose(); newBrush = newRenderTarget.CreateLinearGradientBrush( new LinearGradientBrushProperties( ((LinearGradientBrush)sourceBrush).StartPoint, ((LinearGradientBrush)sourceBrush).EndPoint), newGSC, new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform)); sourceBrush.Dispose(); return newBrush; } if (sourceBrush is RadialGradientBrush) { var oldGSC = ((RadialGradientBrush)sourceBrush).GradientStops; var newGSC = newRenderTarget.CreateGradientStopCollection(oldGSC, oldGSC.ColorInterpolationGamma, oldGSC.ExtendMode); oldGSC.Dispose(); newBrush = newRenderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties( ((RadialGradientBrush)sourceBrush).Center, ((RadialGradientBrush)sourceBrush).GradientOriginOffset, ((RadialGradientBrush)sourceBrush).RadiusX, ((RadialGradientBrush)sourceBrush).RadiusY), newGSC, new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform)); sourceBrush.Dispose(); return newBrush; } if (sourceBrush is BitmapBrush) { newBrush = newRenderTarget.CreateBitmapBrush( Bitmap, new BitmapBrushProperties( ((BitmapBrush)sourceBrush).ExtendModeX, ((BitmapBrush)sourceBrush).ExtendModeY, ((BitmapBrush)sourceBrush).InterpolationMode), new BrushProperties(sourceBrush.Opacity, sourceBrush.Transform)); sourceBrush.Dispose(); return newBrush; } throw new NotImplementedException("Unknown brush type used"); }
public void DrawLegend(Graphics g, float pos_x, float pos_y, float legend_width, float legend_height, float lineHeight, List <IlegendItem> list) { if (!IsLegendVisible) { return; } var pen = new Pen(LegendBorderColor, 1.0F); SolidBrush brush = null; Rectangle legendRect; try { legendRect = new Rectangle((int)pos_x, (int)pos_y, (int)legend_width, (int)legend_height); brush = new SolidBrush(LegendBackColor1); g.FillRectangle(brush, legendRect); if (IsBorderVisible) { g.DrawRectangle(pen, legendRect); } } finally { brush?.Dispose(); } Brush txtBrush = null; try { var row_height = (int)(_spacing + lineHeight); var sq_X = legendRect.X + (int)_spacing; var sq_Y = legendRect.Y + row_height; var rect = new Rectangle(sq_X, sq_Y, (int)legend_width, row_height); var sf = new StringFormat { Alignment = StringAlignment.Near, Trimming = StringTrimming.EllipsisCharacter }; foreach (var item in list) { txtBrush = GetColor(item.ForeGroundColor); // Square DrawSquare(g, rect, item.BackGroundColor); g.DrawString(item.Description, Legendfont, txtBrush, rect.X + 18, rect.Y - 1, sf); // *** One step down. rect.Y += (int)(lineHeight + _spacing); } } finally { txtBrush?.Dispose(); } }
public void Dispose() { bitmap?.Dispose(); stringFormat?.Dispose(); brush?.Dispose(); }
// Adapted from from Audacity, Ruler.cpp private void recalculate() { // Calculate the correct font size based on height int desiredPixelHeight = (this.Size.Height / 3); if (m_font != null) { m_font.Dispose(); } m_font = new Font(Font.FontFamily, desiredPixelHeight, GraphicsUnit.Pixel); if (m_textBrush != null) { m_textBrush.Dispose(); } m_textBrush = new SolidBrush(Color.White); // As a heuristic, we want at least 10 pixels between each minor tick var t = pixelsToTime(10); if (t.TotalSeconds > 0.05) { if (t.TotalSeconds < 0.1) { m_MinorTick = TimeSpan.FromMilliseconds(100); m_minorTicksPerMajor = 5; } else if (t.TotalSeconds < 0.25) { m_MinorTick = TimeSpan.FromMilliseconds(250); m_minorTicksPerMajor = 4; } else if (t.TotalSeconds < 0.5) { m_MinorTick = TimeSpan.FromMilliseconds(500); m_minorTicksPerMajor = 4; } else if (t.TotalSeconds < 1) { m_MinorTick = TimeSpan.FromSeconds(1); m_minorTicksPerMajor = 5; } else if (t.TotalSeconds < 5) { m_MinorTick = TimeSpan.FromSeconds(5); m_minorTicksPerMajor = 6; //major = 30.0; } else if (t.TotalSeconds < 10) { m_MinorTick = TimeSpan.FromSeconds(10); m_minorTicksPerMajor = 6; //major = 60.0; } else if (t.TotalSeconds < 15) { m_MinorTick = TimeSpan.FromSeconds(15); m_minorTicksPerMajor = 4; //major = 60.0; } else if (t.TotalSeconds < 30) { m_MinorTick = TimeSpan.FromSeconds(30); m_minorTicksPerMajor = 4; //major = 120.0; } else if (t.TotalMinutes < 1) { m_MinorTick = TimeSpan.FromMinutes(1); m_minorTicksPerMajor = 5; //major = 300.0; } else if (t.TotalMinutes < 5) { m_MinorTick = TimeSpan.FromMinutes(5); m_minorTicksPerMajor = 3; //major = 900.0; } else if (t.TotalMinutes < 10) { m_MinorTick = TimeSpan.FromMinutes(10); m_minorTicksPerMajor = 3; //major = 1800.0; } else if (t.TotalMinutes < 15) { m_MinorTick = TimeSpan.FromMinutes(15); m_minorTicksPerMajor = 4; //major = 3600.0; } else if (t.TotalMinutes < 30) { m_MinorTick = TimeSpan.FromMinutes(30); m_minorTicksPerMajor = 2; //major = 3600.0; } else if (t.TotalHours < 1) { m_MinorTick = TimeSpan.FromHours(1); m_minorTicksPerMajor = 6; //major = 6 * 3600.0; } else if (t.TotalHours < 6) { m_MinorTick = TimeSpan.FromHours(6); m_minorTicksPerMajor = 4; //major = 24 * 3600.0; } else if (t.TotalDays < 1) { m_MinorTick = TimeSpan.FromDays(1); m_minorTicksPerMajor = 7; //major = 7 * 24 * 3600.0; } else { m_MinorTick = TimeSpan.FromDays(7); m_minorTicksPerMajor = 1; //major = 24.0 * 7.0 * 3600.0; } } else { // Fractional seconds double d = 0.000001; for (;;) { if (t.TotalSeconds < d) { m_MinorTick = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 1000 * d)); m_minorTicksPerMajor = 5; //major = d * 5.0; break; } d *= 5.0; if (t.TotalSeconds < d) { m_MinorTick = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 1000 * d)); m_minorTicksPerMajor = 5; //major = d * 5.0; break; } d *= 5.0; if (t.TotalSeconds < d) { m_MinorTick = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 1000 * d)); m_minorTicksPerMajor = 4; //major = d * 4.0; break; } d *= 4.0; } } //Debug.WriteLine("update(): t={0} minor={1} minPerMaj={2}", t, m_MinorTick, m_minorTicksPerMajor); }
private static void PaintHighlightedCell(ILogPaintContext logPaintCtx, DataGridViewCellPaintingEventArgs e, DataGridView gridView, bool noBackgroundFill, HilightEntry groundEntry) { object value = e.Value != null ? e.Value : ""; IList <HilightMatchEntry> matchList = logPaintCtx.FindHilightMatches(value as string); // too many entries per line seem to cause problems with the GDI while (matchList.Count > 50) { matchList.RemoveAt(50); } var hme = new HilightMatchEntry(); hme.StartPos = 0; hme.Length = (value as string).Length; hme.HilightEntry = new HilightEntry((value as string), groundEntry != null ? groundEntry.ForegroundColor : Color.FromKnownColor(KnownColor.Black), groundEntry != null ? groundEntry.BackgroundColor : Color.Empty, false); matchList = MergeHighlightMatchEntries(matchList, hme); int leftPad = e.CellStyle.Padding.Left; RectangleF rect = new RectangleF(e.CellBounds.Left + leftPad, e.CellBounds.Top, e.CellBounds.Width, e.CellBounds.Height); Rectangle borderWidths = BorderWidths(e.AdvancedBorderStyle); Rectangle valBounds = e.CellBounds; valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; if (e.CellStyle.Padding != Padding.Empty) { valBounds.Offset(e.CellStyle.Padding.Left, e.CellStyle.Padding.Top); valBounds.Width -= e.CellStyle.Padding.Horizontal; valBounds.Height -= e.CellStyle.Padding.Vertical; } TextFormatFlags flags = TextFormatFlags.Left | TextFormatFlags.SingleLine | TextFormatFlags.NoPrefix | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.NoPadding | TextFormatFlags.VerticalCenter | TextFormatFlags.TextBoxControl ; // | TextFormatFlags.VerticalCenter // | TextFormatFlags.TextBoxControl // TextFormatFlags.SingleLine //TextRenderer.DrawText(e.Graphics, e.Value as String, e.CellStyle.Font, valBounds, Color.FromKnownColor(KnownColor.Black), flags); Point wordPos = valBounds.Location; Size proposedSize = new Size(valBounds.Width, valBounds.Height); Rectangle r = gridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); e.Graphics.SetClip(e.CellBounds); foreach (HilightMatchEntry matchEntry in matchList) { Font font = matchEntry != null && matchEntry.HilightEntry.IsBold ? logPaintCtx.BoldFont : logPaintCtx.NormalFont; Brush bgBrush = matchEntry.HilightEntry.BackgroundColor != Color.Empty ? new SolidBrush(matchEntry.HilightEntry.BackgroundColor) : null; string matchWord = (value as string).Substring(matchEntry.StartPos, matchEntry.Length); Size wordSize = TextRenderer.MeasureText(e.Graphics, matchWord, font, proposedSize, flags); wordSize.Height = e.CellBounds.Height; Rectangle wordRect = new Rectangle(wordPos, wordSize); Color foreColor = matchEntry.HilightEntry.ForegroundColor; if ((e.State & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected) { if (!noBackgroundFill && bgBrush != null && !matchEntry.HilightEntry.NoBackground) { e.Graphics.FillRectangle(bgBrush, wordRect); } } else { if (foreColor.Equals(Color.Black)) { foreColor = Color.White; } } TextRenderer.DrawText(e.Graphics, matchWord, font, wordRect, foreColor, flags); wordPos.Offset(wordSize.Width, 0); if (bgBrush != null) { bgBrush.Dispose(); } } }
/// <summary> /// 重绘控件 /// </summary> /// <param name="e"></param> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (BackImg == null) { base.OnPaint(e); return; } int i = (int)state; if (this.Focused && state != State.MouseDown && _IsTabFocus == true) { i = 5; } if (!this.Enabled) { i = 4; } Rectangle rc = this.ClientRectangle; Graphics g = e.Graphics; base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle)); try { if (BackImg != null) { if (_BacklightLTRB != Rectangle.Empty) { ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height), i, 5); } else { ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(10, 10, 10, 10), i, 5); } } } catch { } Image img = null; Size txts, imgs; txts = Size.Empty; imgs = Size.Empty; if (this.Image != null) { img = this.Image; } else if (this.ImageList != null && this.ImageIndex != -1) { img = this.ImageList.Images[this.ImageIndex]; } if (img != null) { imgs.Width = img.Width; imgs.Height = img.Height; } StringFormat format1; using (format1 = new StringFormat()) { format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; SizeF ef1 = g.MeasureString(this.Text, this.Font, new SizeF((float)rc.Width, (float)rc.Height), format1); txts = Size.Ceiling(ef1); } rc.Inflate(-4, -4); if (imgs.Width * imgs.Height != 0) { Rectangle imgr = rc; imgr = ImageDrawRect.HAlignWithin(imgs, imgr, this.ImageAlign); imgr = ImageDrawRect.VAlignWithin(imgs, imgr, this.ImageAlign); if (!this.Enabled) { ControlPaint.DrawImageDisabled(g, img, imgr.Left, imgr.Top, this.BackColor); } else { g.DrawImage(img, imgr.Left, imgr.Top, img.Width, img.Height); } } Rectangle txtr = rc; txtr = ImageDrawRect.HAlignWithin(txts, txtr, this.TextAlign); txtr = ImageDrawRect.VAlignWithin(txts, txtr, this.TextAlign); format1 = new StringFormat(); format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; if (this.RightToLeft == RightToLeft.Yes) { format1.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } brush = new SolidBrush(this.ForeColor); g.DrawString(this.Text, this.Font, brush, (RectangleF)txtr, format1); brush.Dispose(); }