We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PushButton BackColor

Thread ID:





19312 Sep 23,2004 09:54 AM UTC Sep 23,2004 02:27 PM UTC WinForms 1
Tags: GridControl
Charles Phillips
Asked On September 23, 2004 09:54 AM UTC

I''m still very new to the Essentials Grid but I''m learning fast. I am currently stuck on one issue and that is trying to change the BackColor of a PushButton cell type. I can change the backcolor of the cell but of course the button is still its default color. Perhaps I''m just not seeing it? Charles Phillips

Administrator [Syncfusion]
Replied On September 23, 2004 02:27 PM UTC

Hi Charles, By default the grid uses ControlPaint.DrawButton which does not support changing the color. You can however handle the following event: (From ms-help://Syncfusion.EssentialSuiteClassRef/Syncfusion.EssentialSuiteClassRef/Syncfusion.Grid~Syncfusion.Windows.Forms.Grid.GridDrawCellButtonBackgroundEventArgs.html) The DrawCellButtonBackground event allows custom drawing of a cell button elements background. Set the Cancel property true if you have drawn the cell button elements background and do not want the grid to proceed with default drawing of the cell button elements background. 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 also 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. The followin sample demonstrates drawing a custom cell button element background [C#] 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; } Stefan


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon