menu

WinForms

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

    Show / Hide Table of Contents

    Class GridDrawCellButtonBackgroundEventArgs

    Provides data about the cancelable DrawCellButtonBackground event.

    Inheritance
    System.Object
    SyncfusionCancelEventArgs
    GridDrawCellButtonBackgroundEventArgs
    Inherited Members
    SyncfusionCancelEventArgs.ToString()
    Namespace: Syncfusion.Windows.Forms.Grid
    Assembly: Syncfusion.Grid.Windows.dll
    Syntax
    public sealed class GridDrawCellButtonBackgroundEventArgs : SyncfusionCancelEventArgs
    Remarks

    GridDrawCellButtonBackgroundEventArgs is a custom event argument class used by the DrawCellButtonBackground event to allow custom drawing of a cell button elements background. Set the Cancel property true if you have drawn the cell button element's background and do not want the grid to proceed with default drawing.

    The event will automatically be called for every button inside a cell.

    You should handle this event if you want to change for example the background color of pushbuttons and do not want the grid to proceed with its default drawing routine calling ControlPaint.DrawButton. This event supplies you with the current button state that should be drawn. After the background has been drawn, any foreground text will be drawn by the grid.

    Be sure to set e.Cancel to true if you did your own drawing.

    Examples

    The following sample demonstrates drawing a custom cell button element background:

            public static void Draw3dFrame(Graphics g, int x0, int y0, int x1, int y1, int w, Color rgbTopLeft, Color rgbBottomRight)
            {
                Rectangle rc;
                for (int i = 0; i != w; i++)
                {
                    // Top
                    Brush brTL = new SolidBrush(rgbTopLeft);
                    rc = Rectangle.FromLTRB(x0, y0, x1, y0+1);
                    g.FillRectangle(brTL, rc);
                    // Left
                    rc = Rectangle.FromLTRB(x0, y0, x0+1, y1);
                    g.FillRectangle(brTL, rc);
                    brTL.Dispose();
                    Brush brBR = new SolidBrush(rgbBottomRight);
                    // Bottom
                    rc = Rectangle.FromLTRB(x0, y1, x1+1, y1+1);
                    g.FillRectangle(brBR, rc);
                    // Right
                    rc = Rectangle.FromLTRB(x1, y0, x1+1, y1);
                    g.FillRectangle(brBR, rc);
                    brBR.Dispose();
                    if (i != w-1)
                    {
                        x0++;
                        y0++;
                        x1--;
                        y1--;
                    }
                }
            }
            protected override void OnDrawCellButtonBackground(GridDrawCellButtonBackgroundEventArgs e)
            {
                bool drawPressed = (e.ButtonState & ButtonState.Pushed) != 0;
                Rectangle rect = e.Bounds;
                Graphics g = e.Graphics;
                Color hilight = SystemColors.ControlLightLight;
                Color shadow = SystemColors.ControlDarkDark;
                if (!drawPressed)
                {
                    Draw3dFrame(e.Graphics, rect.Left, rect.Top, rect.Right-1, rect.Bottom-1, 1,
                        hilight, shadow);
                }
                else
                {
                    Brush br = new SolidBrush(shadow);
                    g.FillRectangle(br, Rectangle.FromLTRB(rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom));
                    g.FillRectangle(br, Rectangle.FromLTRB(rect.Right-1, rect.Top, rect.Right, rect.Bottom));
                    br.Dispose();
                }
                e.Cancel = true;
            }

    Constructors

    GridDrawCellButtonBackgroundEventArgs(GridCellButton, Graphics, Rectangle, ButtonState, GridStyleInfo)

    Initializes a GridDrawCellButtonBackgroundEventArgs object.

    Declaration
    public GridDrawCellButtonBackgroundEventArgs(GridCellButton button, Graphics graphics, Rectangle bounds, ButtonState buttonState, GridStyleInfo style)
    Parameters
    Type Name Description
    GridCellButton button

    The GridCellButton to be drawn.

    System.Drawing.Graphics graphics

    The System.Drawing.Graphics context of the canvas.

    System.Drawing.Rectangle bounds

    The System.Drawing.Rectangle with the bounds.

    System.Windows.Forms.ButtonState buttonState

    A System.Windows.Form.ButtonState that specifies the current state.

    GridStyleInfo style

    The GridStyleInfo object that holds cell information.

    Properties

    Bounds

    Gets the System.Drawing.Rectangle with the bounds.

    Declaration
    [TraceProperty(true)]
    public Rectangle Bounds { get; }
    Property Value
    Type Description
    System.Drawing.Rectangle

    Button

    Gets the GridCellButton to be drawn.

    Declaration
    [TraceProperty(true)]
    public GridCellButton Button { get; }
    Property Value
    Type Description
    GridCellButton

    ButtonState

    Gets a ButtonState that specifies the current state.

    Declaration
    [TraceProperty(true)]
    public ButtonState ButtonState { get; }
    Property Value
    Type Description
    System.Windows.Forms.ButtonState

    Graphics

    Gets the System.Drawing.Graphics context of the canvas.

    Declaration
    [TraceProperty(true)]
    public Graphics Graphics { get; }
    Property Value
    Type Description
    System.Drawing.Graphics

    Style

    Gets the GridStyleInfo object that holds cell information.

    Declaration
    public GridStyleInfo Style { get; }
    Property Value
    Type Description
    GridStyleInfo

    See Also

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