2

この図では... ここに画像の説明を入力 ...各「線の色」ラベルの横に色付きの円があることがわかります。

私のプロジェクトでは、色付きの円は Swatch です。Swatch のコード ファイル全体は次のとおりです。

public class Swatch : System.Windows.Forms.Panel
{
    /*private int _Radius = 20;

    [System.ComponentModel.Category("Layout")]
    public int Radius
    {
        get { return _Radius; }
        set { _Radius = value; }
    } */
    private System.Drawing.Color _BorderColor = System.Drawing.Color.Transparent;

    [System.ComponentModel.Category("Appearance")]
    public System.Drawing.Color BorderColor
    {
        get { return _BorderColor; }
        set { _BorderColor = value; }
    }

    private System.Drawing.Color _FillColor = System.Drawing.Color.Blue;

    [System.ComponentModel.Category("Appearance")]
    public System.Drawing.Color FillColor
    {
        get { return _FillColor; }
        set { _FillColor = value; }
    }

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        base.OnPaint(e);
        System.Drawing.Rectangle RealRect = new System.Drawing.Rectangle(e.ClipRectangle.Location, e.ClipRectangle.Size);
        RealRect.Inflate(-1, -1);

        int Radius = Math.Min(RealRect.Size.Height, RealRect.Size.Width);
        System.Drawing.Rectangle SqRect = new System.Drawing.Rectangle();
        SqRect.Location = RealRect.Location;
        SqRect.Size = new System.Drawing.Size(Radius, Radius);

        System.Drawing.Drawing2D.CompositingQuality PrevQual = e.Graphics.CompositingQuality;
        using (System.Drawing.SolidBrush Back = new System.Drawing.SolidBrush(this.FillColor))
        {
            using (System.Drawing.Pen Pen = new System.Drawing.Pen(new System.Drawing.SolidBrush(this.BorderColor)))
            {
                //e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                e.Graphics.FillEllipse(Back, SqRect);
                e.Graphics.DrawEllipse(Pen, SqRect);
            }
        }

        e.Graphics.CompositingQuality = PrevQual;
    }

    public Swatch()
    {
        this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
        this.SetStyle(System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer, true);
        this.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
        this.SetStyle(System.Windows.Forms.ControlStyles.ResizeRedraw, true);
        this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);
        this.DoubleBuffered = true;
    }
}

各行は、TableLayoutPanel、ラベル、Swatch コントロール、および NumericUpDown ボックスで構成される UserControl です。

約 10 行あり、タブ コントロールの TabPage 内にある TableLayoutPanel に配置されます。オーバーフローによりタブ ページがスクロールするように、タブ ページが にAutoScroll設定されています。true

問題は、アプリケーションを実行して上下にスクロールするたびに、上の図に示すように、スウォッチ (色付きの円) が破れてあらゆる種類のアーティファクトが表示されることです。レンダリング アーティファクトのないクリーンなスクロールが必要です。

私は使用してみましたSetStyle(ここで示唆されているように Windows フォームのペイントの問題) が、効果はありませんでした。

UserControl (各行) は にDoubleBuffered設定されてtrueおり、それも効果がありませんでした。

かなり明白な何かが欠けているのではないかと心配しています。

4

1 に答える 1

4

問題は、クリッピング四角形に基づいて円の半径を計算することです。そのため、線が部分的にしか見えない場合、悪い値が生じます。

基本クラスによって提供される実際の長方形に基づいて計算し、通常どおり切り取る必要があります。

于 2013-01-02T23:05:50.307 に答える