0
private void Container_Paint(object sender, PaintEventArgs e)
{
    //e.Graphics.TranslateTransform(printersContainer.AutoScrollPosition.X, printersContainer.AutoScrollPosition.Y);

    Pen printerBorderPen = new Pen(ColorCode.BorderForm, 3);


    foreach (Control c in this.Controls)
    {
        if (c is ucPrinterControl)
        {
            Graphics graphics = c.CreateGraphics();
            graphics.DrawRectangle(printerBorderPen, e.ClipRectangle.Left, e.ClipRectangle.Top, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
        }
    }

    Pen formBorderPen = new Pen(ColorCode.BorderForm, 3);

    e.Graphics.DrawRectangle(formBorderPen, new Rectangle(0, 0, Container.Width, Container.Height));
}

As seen in the code above I use Graphics to draw rectangular widgets in the UI application that I am creating. When I use auto scrolling the widgets that were previously not visible (under the current view) get viewed but displayed as empty. Same happens when I scroll u again. But when I minimize and unminimize the window it all gets appeared in the current view.

As seen on the above code I used TranslateTransform but it didn't solve the problem.

M. Schena
  • 2,039
  • 1
  • 21
  • 29
Janitha Tennakoon
  • 856
  • 11
  • 40
  • Graphics created from control.CreateGraphics are not recommended for actually drawing on the controls. The function is only for either measuring etc or for creating non-persistent graphics like a rubber-band line. To draw those borders outside the controls use the paint event's graphics object. To draw them onto the controls invalidate them and draw in each one's respective paint event! – TaW Feb 02 '16 at 10:17
  • You are complaining about incorrectly using the e.ClipRectangle property, it has nothing to do with the rectangle around c. Use c.Bounds instead. TranslateTransform() is required. – Hans Passant Feb 02 '16 at 11:05
  • I have changed the code to use c.Bound and enabled TranslateTransform(). But still has the issue when scrolling. – Janitha Tennakoon Feb 02 '16 at 12:40

0 Answers0