滚动时的人工制品

时间:2014-04-07 09:08:26

标签: c# winforms user-interface gdi visual-artifacts

Re-pro步骤:

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

观察撕裂/伪影。我该怎么做才能解决这个问题?

enter image description here

代码:

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

多数民众赞成

0 个答案:

没有答案