Skip to main content

Performance Issues

Comments

5 comments

  • Dapfor Team

    Dear Deepak,

    You shouldn't call setters of the e.Cell.Appearance inside of the e.PaintCell event because this call will store a new value per cell and invoke Control.Invalidate() method. This leads to the recursion. Instead you should use PaintCellEventArgs.Appearance property as follows:

     

    case "BidPrc":
    if (marketDisplayModel.IsOnBid)
    {
    Color sColor = this.OrderOnMarketColor;
    e.Appearance.ForeColor = sColor;
    }
    ...

     

    Best regards,

    Dapfor

     

     

     

     

    0
  • Michael Sage

    Thanks, that definitely helped.

    0
  • Michael Sage

    Hi,

    I had a follow up question , I'm trying to draw a border around the cell for which I have set the fore color. To get the border to display, I used e.PaintAll() and e.Handled = true in the Paint Cell Event.  It seems like when I use the e.PaintAll() and e.Handled = true, the forecolor of the cell is always white, it doesn't display the color I have set it to. Can you tell me what I'm doing wrong here. I have listed my code below.

     

    Thanks.

    case "BidPrc":
    e.PaintAll();
    e.Handled = true;
    if (marketDisplayModel.IsOnBid)
    {
    Color sColor = this.OrderOnMarketColor;
    e.Appearance.ForeColor = sColor;
    using (Pen pn = new Pen(sColor))
    {
    Rectangle rect2 = new Rectangle(e.Cell.VisibleBounds.X, e.Cell.VisibleBounds.Location.Y, e.Cell.VirtualBounds.Width - 1, e.Cell.VisibleBounds.Height - 1);
    e.Graphics.DrawRectangle(pn, rect2);
    pn.Dispose();
    }
    }
    else
    {
    e.Appearance.ForeColor = e.Cell.Column.Appearance.CaptionColor.ForeColor;
    }
    e.Appearance.ForeColor = e.Cell.Column.Appearance.CaptionColor.ForeColor;

     

     

    0
  • Michael Sage

    The last line got inserted by mistake, it should really be 

    case "BidPrc":
    e.PaintAll();
    e.Handled = true;
    if (marketDisplayModel.IsOnBid)
    {
    Color sColor = this.OrderOnMarketColor;
    e.Appearance.ForeColor = sColor;
    using (Pen pn = new Pen(sColor))
    {
    Rectangle rect2 = new Rectangle(e.Cell.VisibleBounds.X, e.Cell.VisibleBounds.Location.Y, e.Cell.VirtualBounds.Width - 1, e.Cell.VisibleBounds.Height - 1);
    e.Graphics.DrawRectangle(pn, rect2);
    pn.Dispose();
    }
    }
    else
    {
    e.Appearance.ForeColor = e.Cell.Column.Appearance.CaptionColor.ForeColor;
    }

    e.Appearance.BackColor = e.Cell.Column.Appearance.CaptionColor.BackColor;

    0
  • Dapfor Team

    Hello Deepak,

    Firstly you should draw the background and then prevent the cell from the next painting. Then you can do any painting you want and also modify any color in the e.Appearance property. If the e.Handled isn't set, then the grid will call e.PaintAll(). It verifies which parts of the cell should be painted and paints everything without background.

     

    case "BidPrc":
        //1. Draw a background
        e.PaintBackground();

        //2. Prevent the cell from background painting
        e.Parts ^= e.Parts & PaintPart.Background;

    //3. Add your custom drawing:
    if (marketDisplayModel.IsOnBid)
    {
    Color sColor = this.OrderOnMarketColor;
    e.Appearance.ForeColor = sColor;
    using (Pen pn = new Pen(sColor))
    {
    Rectangle rect2 = new Rectangle(e.Cell.VisibleBounds.X,
    e.Cell.VisibleBounds.Location.Y,
    e.Cell.VirtualBounds.Width - 1,
    e.Cell.VisibleBounds.Height - 1);
    e.Graphics.DrawRectangle(pn, rect2);
    }
    }
    else
    {
    e.Appearance.ForeColor = e.Cell.Column.Appearance.CaptionColor.ForeColor;
    }
    e.Appearance.BackColor = e.Cell.Column.Appearance.CaptionColor.BackColor;

     

    P.S. You call the pn.Dispose() twice: explicitly and in the end of 'using' directive.

     

     

    0

Please sign in to leave a comment.

Powered by Zendesk