menu

WinForms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class GridGdiPaint - API Reference

    Show / Hide Table of Contents

    Class GridGdiPaint

    Provides a set of advanced GDI Interop drawing routines that can be used instead of GDI plus routines to optimize drawing performance of the grid. Call these methods from DrawCellDisplayText and FillRectangleHook as shown in example. You might also try turning off double buffering.

    Inheritance
    System.Object
    GridGdiPaint
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: Syncfusion.Windows.Forms.Grid
    Assembly: Syncfusion.Grid.Windows.dll
    Syntax
    public class GridGdiPaint
    Examples
    protected override void OnDrawCellDisplayText(GridDrawCellDisplayTextEventArgs e)
    {
           base.OnDrawCellDisplayText (e);
    

    GridGdiPaint.AllowTextOut = false; if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.DrawText(e.Graphics, e.DisplayText, e.TextRectangle, e.Style); }

    protected override void OnFillRectangleHook(GridFillRectangleHookEventArgs e) { base.OnFillRectangleHook (e);

    if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.FillRectangle(e.Graphics, e.Bounds, e.Brush); }

    - Or -

    public class PerformanceGridControl : GridControl { private bool useGDI;

    ///

    /// Property UseGDI (bool) /// public bool UseGDI { get { return this.useGDI; } set { if (this.UseGDI != value) { this.useGDI = value; Invalidate(); } } }

    private bool useDoubleBuffer = true;

    public bool UseDoubleBuffer { get { return this.useDoubleBuffer; } set { if (this.useDoubleBuffer != value) { this.useDoubleBuffer = value; SetStyle(ControlStyles.Opaque, value); SetStyle(ControlStyles.DoubleBuffer, value); } } }

    protected override void OnPaintBackground(PaintEventArgs pevent) { if (useDoubleBuffer) base.OnPaintBackground (pevent); }

    protected override void OnDrawCellDisplayText(GridDrawCellDisplayTextEventArgs e) { base.OnDrawCellDisplayText (e);

    if (!useGDI || e.Cancel) return;

    e.Cancel = GridGdiPaint.Instance.DrawText(e.Graphics, e.DisplayText, e.TextRectangle, e.Style); }

    protected override void OnFillRectangleHook(GridFillRectangleHookEventArgs e) { base.OnFillRectangleHook (e);

    if (!useGDI || e.Cancel) return;

    e.Cancel = GridGdiPaint.Instance.FillRectangle(e.Graphics, e.Bounds, e.Brush); } }

    Fields

    AllowTextOut

    Specifies if GDI TextOut routine can be used as is when text is left-aligned and top-aligned. Set this false if text might need to be clipped.

    Declaration
    public static bool AllowTextOut
    Field Value
    Type Description
    System.Boolean

    ForceDrawText

    Specifies if GDI DrawText routine should always be used and text should be clipped. When you set this true the performance of the GDI drawing routine will be the same as for GDIplus DrawString since text needs to be clipped every time it is drawn. If you want to force GDI DrawText on a cell by cell basis you can specify style.Trimming = System.Drawing.StringTrimming.Character instead and leave ForceDrawText = false.

    Declaration
    public static bool ForceDrawText
    Field Value
    Type Description
    System.Boolean

    Properties

    Instance

    Gets an instance of this calls

    Declaration
    public static GridGdiPaint Instance { get; }
    Property Value
    Type Description
    GridGdiPaint

    Methods

    DrawText(Graphics, String, Rectangle, GridStyleInfo)

    Draws the text emulating the Graphics.DrawString method if possible.

    Declaration
    public bool DrawText(Graphics g, string displayText, Rectangle textRectangle, GridStyleInfo style)
    Parameters
    Type Name Description
    System.Drawing.Graphics g

    Graphics context.

    System.String displayText

    Display text.

    System.Drawing.Rectangle textRectangle

    Text rectangle.

    GridStyleInfo style

    Cell style information.

    Returns
    Type Description
    System.Boolean

    true if text could be painted; false if text could not be painted (e.g. because it needs to be drawn rotated).

    Examples
    protected override void OnDrawCellDisplayText(GridDrawCellDisplayTextEventArgs e)
    {
           base.OnDrawCellDisplayText (e);
    

    GridGdiPaint.AllowTextOut = false; if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.DrawText(e.Graphics, e.DisplayText, e.TextRectangle, e.Style, e.Bounds); }

    protected override void OnFillRectangleHook(GridFillRectangleHookEventArgs e) { base.OnFillRectangleHook (e);

    if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.FillRectangle(e.Graphics, e.Bounds, e.Brush); }

    DrawText(Graphics, String, Rectangle, GridStyleInfo, Rectangle)

    Draws the text emulating the Graphics.DrawString method if possible.

    Declaration
    public bool DrawText(Graphics g, string displayText, Rectangle textRectangle, GridStyleInfo style, Rectangle clipBounds)
    Parameters
    Type Name Description
    System.Drawing.Graphics g

    Graphics context.

    System.String displayText

    Display text.

    System.Drawing.Rectangle textRectangle

    Text rectangle.

    GridStyleInfo style

    Cell style information.

    System.Drawing.Rectangle clipBounds

    The clip bounds of the text. When empty or same as textRectangle there will be no explicit clipping (but this does not affect DT_NOCLIP setting of GDI DrawText routine). If specified then output will be clipped by setting IntersectClipRect and DT_NOCLIP option is used for DrawText.

    Returns
    Type Description
    System.Boolean

    true if text could be painted; false if text could not be painted (e.g. because it needs to be drawn rotated).

    Examples
    protected override void OnDrawCellDisplayText(GridDrawCellDisplayTextEventArgs e)
    {
           base.OnDrawCellDisplayText (e);
    

    GridGdiPaint.AllowTextOut = false; if (!e.Cancel) { GridControlBase grid = (GridControlBase) sender; Rectangle clipBounds = grid.ViewLayout.RangeInfoToRectangle(GridRangeInfo.Cell(e.Style.CellIdentity.RowIndex, e.Style.CellIdentity.ColIndex), GridCellSizeKind.VisibleSize); e.Cancel = GridGdiPaint.Instance.DrawText(e.Graphics, e.DisplayText, e.TextRectangle, e.Style, e.Bounds, clipBounds); } }

    protected override void OnFillRectangleHook(GridFillRectangleHookEventArgs e) { base.OnFillRectangleHook (e);

    if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.FillRectangle(e.Graphics, e.Bounds, e.Brush); }

    DrawText(Graphics, String, Rectangle, GridStyleInfo, Rectangle, Boolean)

    Draws the text emulating the Graphics.DrawString method if possible.

    Declaration
    public bool DrawText(Graphics g, string displayText, Rectangle textRectangle, GridStyleInfo style, Rectangle clipBounds, bool isRightToLeft)
    Parameters
    Type Name Description
    System.Drawing.Graphics g

    Graphics context.

    System.String displayText

    Display text.

    System.Drawing.Rectangle textRectangle

    Text rectangle.

    GridStyleInfo style

    Cell style information.

    System.Drawing.Rectangle clipBounds

    The clip bounds of the text. When empty or same as textRectangle there will be no explicit clipping (but this does not affect DT_NOCLIP setting of GDI DrawText routine). If specified then output will be clipped by setting IntersectClipRect and DT_NOCLIP option is used for DrawText.

    System.Boolean isRightToLeft

    true for RTL languages, false if left to right. Affects Horizontal Alignemnt.

    Returns
    Type Description
    System.Boolean

    true if text could be painted; false if text could not be painted (e.g. because it needs to be drawn rotated).

    Examples
    protected override void OnDrawCellDisplayText(GridDrawCellDisplayTextEventArgs e)
    {
           base.OnDrawCellDisplayText (e);
    

    GridGdiPaint.AllowTextOut = false; if (!e.Cancel) { GridControlBase grid = (GridControlBase) sender; Rectangle clipBounds = grid.ViewLayout.RangeInfoToRectangle(GridRangeInfo.Cell(e.Style.CellIdentity.RowIndex, e.Style.CellIdentity.ColIndex), GridCellSizeKind.VisibleSize); e.Cancel = GridGdiPaint.Instance.DrawText(e.Graphics, e.DisplayText, e.TextRectangle, e.Style, e.Bounds, clipBounds); } }

    protected override void OnFillRectangleHook(GridFillRectangleHookEventArgs e) { base.OnFillRectangleHook (e);

    if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.FillRectangle(e.Graphics, e.Bounds, e.Brush); }

    FillRectangle(Graphics, RectangleF, BrushInfo)

    Fills the specified rectangle with the specified brush emulating Graphics.FillRectangle method

    Declaration
    public bool FillRectangle(Graphics graphics, RectangleF bounds, BrushInfo brush)
    Parameters
    Type Name Description
    System.Drawing.Graphics graphics

    Graphics context.

    System.Drawing.RectangleF bounds

    Rectangle bounds.

    BrushInfo brush

    Fill brush.

    Returns
    Type Description
    System.Boolean

    true if text could be painted; false if text could not be painted (e.g. color is alphablended or gradient).

    Examples
    protected override void OnDrawCellDisplayText(GridDrawCellDisplayTextEventArgs e)
    {
           base.OnDrawCellDisplayText (e);
    

    GridGdiPaint.AllowTextOut = false; if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.DrawText(e.Graphics, e.DisplayText, e.TextRectangle, e.Style); }

    protected override void OnFillRectangleHook(GridFillRectangleHookEventArgs e) { base.OnFillRectangleHook (e);

    if (!e.Cancel) e.Cancel = GridGdiPaint.Instance.FillRectangle(e.Graphics, e.Bounds, e.Brush); }

    Back to top Generated by DocFX
    Copyright © 2001 - 2023 Syncfusion Inc. All Rights Reserved