0

.net 2.0 Windows フォーム アプリを作成し、splitContainer ドッキングされた Fill を追加し、これをフォーム コンストラクターに追加します。

public Form1()
{
    InitializeComponent();

    for (int i = 1; i <= 300; i++)
    {
        FlowLayoutPanel f = new FlowLayoutPanel();
        f.Dock = DockStyle.Fill;
        Button b = new Button();
        f.Controls.Add(b);
        splitContainer1.Panel2.Controls.Add(f);
    }
}

F5 を押します。フォームの右下端をつかみ、すばやくドラッグしてフォームを展開します。すべてのコントロールで作業が行われるため、フォームはかなりぎくしゃくして拡張されます。

同様に遅くなったいくつかの遅いコントロールを含むフォームを含むアプリがあります。違いは、私のアプリでは、マウスでフォームをドラッグすると、ギャップに一瞬醜い黒いスペースが表示されることです。ウィンドウが正しく再描画されていません。この醜い黒いスペースは、上記のサンプル コードには表示されません。

遅いフォームを展開するときに黒いスペースが表示される原因となるアイデアはありますか?

ダブルバッファリングを試しましたが、違いはありません。

編集:これを再現できるように、フォームを基本に分解しました。WindowsFormsApplication_SampleFault という新しい C# Windows フォーム アプリケーションを開始します。以下のコードを Form1.cs に貼り付けます

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security.Principal;
using System.Runtime.InteropServices;


namespace WindowsFormsApplication_SampleFault
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            for (int i = 1; i <= 200; i++)
            {
                Button b = new Button();
                b.Dock = DockStyle.Fill;
                this.Controls.Add(b);
            } 
        }
        }
}

次に、これを Form1.Designer.cs に貼り付けます

namespace WindowsFormsApplication_SampleFault
{
    partial class Form1
    {
            /// <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.statusStrip1 = new System.Windows.Forms.StatusStrip();
            this.SuspendLayout();
            // 
            // statusStrip1
            // 
            this.statusStrip1.Location = new System.Drawing.Point(0, 472);
            this.statusStrip1.Name = "statusStrip1";
            this.statusStrip1.Size = new System.Drawing.Size(756, 22);
            this.statusStrip1.TabIndex = 6;
            this.statusStrip1.Text = "statusStrip1";
            // 
            // frmOptions
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(756, 494);
            this.Controls.Add(this.statusStrip1);
            this.DoubleBuffered = true;
            this.ImeMode = System.Windows.Forms.ImeMode.Off;
            this.MinimizeBox = false;
            this.MinimumSize = new System.Drawing.Size(750, 500);
            this.Name = "frmOptions";
            this.ShowIcon = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.StatusStrip statusStrip1;

    }
}

F5 キーを押して、フォームをドラッグアウトしてみます。黒い領域を生成するために、意図的に再描画メカニズムをオーバーロードしていることに注意してください。

フォーム デザイナーのコードに何か問題があると思いますが、何が原因かわかりません。

4

1 に答える 1

0

この特定のケースは、WS_EX_COMPOSITED によって簡単に修正できます。

const int WS_EX_COMPOSITED = 0x02000000;
protected override CreateParams CreateParams
{
    get
    {
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= WS_EX_COMPOSITED;
        return cp;
    }
}

PS 200 のボタンはどの GUI にも多すぎます :)

私見では

編集済み: ここでは、Win7 でブラック ボックスを修正するために私が何とかしたことを投稿します。コードは少し醜いですが、アイデアは明らかです。

public Form1()
{
    InitializeComponent();

    for (int i = 1; i <= 200; i++)
    {
        Button b = new Button();
        b.Dock = DockStyle.Fill;
        this.Controls.Add(b);
    }
    _layoutWorker.Tick += new EventHandler(LayoutWorker_Tick);

}

private void LayoutWorker_Tick(object sender, EventArgs e)
{
    _layoutWorker.Stop();
    this.PerformLayout();
}

protected override void OnResize(EventArgs e)
{
    this.SuspendLayout();
    base.OnResize(e);
    this.ResumeLayout(false);
    _layoutWorker.Start();
}

private Timer _layoutWorker = new Timer { Enabled = false, Interval = 1 };
于 2010-10-16T18:35:07.600 に答える