views:

23

answers:

1

In my tool I use a a panel to change pages. Each page has it's own panel and when I change a page I send the panel with the controls. On the panel I use as the canvas I have the following paint event:

    private void panelContent_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

        // Paints a border around the panel to match the treeview control
        e.Graphics.DrawRectangle(Pens.CornflowerBlue,
            e.ClipRectangle.Left,
            e.ClipRectangle.Top,
            e.ClipRectangle.Width - 1,
            e.ClipRectangle.Height - 1);

        e.Graphics.Flush();

        base.OnPaint(e);
    }

This method basically draws a nice border around the panel so it look better. For some reason when I move a another form above this panel the lines that make up the border start to run a little. Occasionally small lines will be drawn from the border too. The problem only happens for a few seconds before the entire panel redraws again. Is there anything I can do to prevent this from happening?

A: 

ClipRectangle tells you what part of the control needs to be repainted. If you're moving something over it, this is probably going to be the intersection of your object and the one being moved. You can use this information to more efficiently repaint your control.

You probably want to draw the rectangle from (0, 0) to (panelContent.Width-1, panelContent.Height-1).

Joseph
Works like a charm: private void panelContent_Paint(object sender, PaintEventArgs e) { e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.DrawRectangle(Pens.CornflowerBlue, 0, 0, panelContent.Width - 1, panelContent.Height - 1); e.Graphics.Flush(); base.OnPaint(e); }Thank you!
Icono123