0

复亲步骤:

  • 将流布局面板添加到空的 windows 窗体。
  • 启用自动滚动。
  • 用 100-200 个彩色面板填充它。
  • 尝试上下滚动。

观察撕裂/伪影。我能做些什么来解决这个问题?

在此处输入图像描述

代码:

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);
        }
    }
}

而已

4

0 回答 0