0

Re-pro steps:

  • Add a flow layout panel to an empty windows form.
  • Enable auto-scrolling.
  • Populate it with 100-200 coloured panels.
  • Try scrolling up and down.

Observe tearing/artifacting. What can I do to remedy this?

enter image description here

Code:

partial class TestForm
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.oFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
        this.SuspendLayout();
        // 
        // oFlowLayoutPanel
        // 
        this.oFlowLayoutPanel.AutoScroll = true;
        this.oFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
        this.oFlowLayoutPanel.Location = new System.Drawing.Point(0, 0);
        this.oFlowLayoutPanel.Name = "oFlowLayoutPanel";
        this.oFlowLayoutPanel.Size = new System.Drawing.Size(166, 263);
        this.oFlowLayoutPanel.TabIndex = 0;

        // 
        // TestForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(166, 263);
        this.Controls.Add(this.oFlowLayoutPanel);
        this.DoubleBuffered = true;
        this.Name = "TestForm";
        this.Text = "TestForm";
        this.ResumeLayout(false);

    }

    #endregion

    private FlowLayoutPanel oFlowLayoutPanel;
}

public partial class TestForm : Form
{
    public TestForm()
    {
        InitializeComponent();

        AddPanels();
    }

    private void AddPanels()
    {
        for (int i = 0; i < 200; i++)
        {
            var oPanel = new Panel();
            oPanel.BorderStyle = BorderStyle.FixedSingle;
            oPanel.BackColor = Color.DarkSlateGray;
            oFlowLayoutPanel.Controls.Add(oPanel);
        }
    }
}

Thats it

rupertmulrenan
  • 355
  • 1
  • 3
  • 13
  • I've just tried this - it scrolls with no artefacts. Can you post the code where you populate the flow layout with 200 panels? – Baldrick Apr 07 '14 at 09:21
  • After InitializeComponent() (Where the flow layout panel is added to the form and has its AutoScroll property set) there is a loop. Inside this a new panel is created, its Color is set and at the end of the loop it is added to the flow layout panel Controls collection. – rupertmulrenan Apr 07 '14 at 10:51
  • This only goes wrong if you also use the panel's Paint event. You must call Graphics.TranslateTransform() to offset what you draw by the panel's AutoScrollPosition. Your question is not sufficiently documented. – Hans Passant Apr 07 '14 at 11:22
  • @rupertmulrenan: Please post your code above - it'll make things much easier to diagnose! – Baldrick Apr 07 '14 at 11:30
  • Code added as requested – rupertmulrenan Apr 07 '14 at 11:59
  • Your code still doesn't reproduce the problem. – LarsTech Apr 07 '14 at 14:36
  • So if it occurs on my machine but not on yours are we saying its a driver issue? I have seen that behaviour on multiple machines – rupertmulrenan Apr 08 '14 at 10:45
  • Try adding a few controls (3-4) in each panel that makes it worse – rupertmulrenan Apr 11 '14 at 11:44

0 Answers0