0

私はパネルのダブル バッファリングをあらゆる場所で探しましたが、どれも非常に紛らわしい用語を使用しています。私はバイオリズムをグラフ化しており、バイオリズムをゆっくりと前進させる移動機能が必要です。ただし、頻繁に点滅するので、それを止める方法を見つける必要があります。スレッド化しようとしましたが、スレッド化によってまだちらつきが発生したため、役に立ちませんでした。

タイマーの内部は次のとおりです。一番下までスキップして、グラフィックスがどこに描画されるかを確認できます。基本的に、ポイントを更新、計算、およびプロットします。

  Panel p = panel1;
        p.Refresh();
        double physical = Math.Sin(2 * Math.PI * t / 23) * 100;
        double emotional = Math.Sin(2 * Math.PI * t / 28) * 100;
        double intellectual = Math.Sin(2 * Math.PI * t / 33) * 100;
        double physicalint = int.Parse(Math.Round(physical).ToString());
        double emotionalint = int.Parse(Math.Round(emotional).ToString());
        double intellectualint = int.Parse(Math.Round(intellectual).ToString());

        Console.WriteLine(physical + " Physical, " + emotional + " Emotional, " + intellectual + " Intellectual.");
        Console.WriteLine(physicalint + " Physical, " + emotionalint + " Emotional, " + intellectualint + " Intellectual.");

        int midpt = p.Width / 2;
        double Mastery = (physicalint + intellectualint) / 2;
        double Passion = (physicalint + emotionalint) / 2;
        double Wisdom = (emotionalint + intellectualint) / 2;
        int mastery = int.Parse(Math.Round(Mastery).ToString());
         int passion = int.Parse(Math.Round(Passion).ToString());
         int wisdom = int.Parse(Math.Round(Wisdom).ToString());
        Results.Text = "Primary Biorhythms\nPhysical: " + physicalint.ToString() + "\nEmotional: " + emotionalint.ToString() + "\nIntellectual: " + intellectualint.ToString();
        Results.Text += "\nSecondary Biorhythms\nWisdom: " + wisdom.ToString() + "\nPassion: " + passion.ToString() + "\nMastery: " + mastery.ToString();


        int eanum = int.Parse(Spread.Text);

        if (mode == 0)
        {


            for (int i = -eanum; i <= eanum; i++)
            {
                double actualheightphy = p.Height / 2;
                double physical2 = Math.Sin(2 * Math.PI * (t + i) / 23) * 100;
                double emotional2 = Math.Sin(2 * Math.PI * (t + i) / 28) * 100;
                double intellectual2 = Math.Sin(2 * Math.PI * (t + i) / 33) * 100;
                if (physical2 < 0) { physical2 = physical2 * 1.45; }
                if (physical2 > 0) { physical2 = physical2 * 1.5; }
                if (emotional2 < 0) { emotional2 = emotional2 * 1.45; }
                if (emotional2 > 0) { emotional2 = emotional2 * 1.5; }
                if (intellectual2 < 0) { intellectual2 = intellectual2 * 1.45; }
                if (intellectual2 > 0) { intellectual2 = intellectual2 * 1.5; }
                actualheightphy -= physical2;
                double actualheightemo = p.Height / 2;
                double actualheightint = p.Height / 2;
                actualheightemo -= emotional2;
                actualheightint -= intellectual2;
                int distancebetween = p.Width / eanum;

                p.CreateGraphics().FillEllipse(Brushes.Red, i * distancebetween + midpt - 5, int.Parse(Math.Round(actualheightphy).ToString()) - 5, 10, 10);
                p.CreateGraphics().FillEllipse(Brushes.Blue, i * distancebetween + midpt - 5, int.Parse(Math.Round(actualheightemo).ToString()) - 5, 10, 10);
                p.CreateGraphics().FillEllipse(Brushes.Green, i * distancebetween + midpt - 5, int.Parse(Math.Round(actualheightint).ToString()) - 5, 10, 10);
                if (i % 7 == 0)
                {
                    p.CreateGraphics().DrawString(i.ToString(), new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), Brushes.White, new RectangleF(i * distancebetween + midpt - 5, p.Height - 12, 30, 30));
                }
                if (eanum == 7)
                {
                    p.CreateGraphics().DrawString(i.ToString(), new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), Brushes.White, new RectangleF(i * distancebetween + midpt - 5, p.Height - 12, 30, 30));

                }
            }
            p.CreateGraphics().DrawLine(Pens.White, 0, (p.Height) / 2, p.Width, (p.Height) / 2);
            p.CreateGraphics().DrawLine(Pens.White, p.Width / 2, 0, p.Width / 2, p.Height);

            this.CreateGraphics().DrawString("100", new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular), Brushes.Black, new RectangleF(p.Width / 2 + p.Left - 15, -1, 100, 100));
            this.CreateGraphics().DrawString("-100", new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular), Brushes.Black, new RectangleF(p.Width / 2 + p.Left - 15, p.Height + p.Top + 1, 100, 100));
        }
4

1 に答える 1

0

CreateGraphicsメソッドの性質上、何かを描画するたびに新しい Graphics オブジェクトを作成している可能性があります。どちらが引けるかは運次第なので、大きくちらつくと思います。

そのため、p.CreateGraphics() の戻り値を取得し、それを複数回呼び出すのではなく、すべての描画に再利用します例:

p.CreateGraphics().FillEllipse(...);
p.CreateGraphics().FillEllipse(...);
p.CreateGraphics().FillEllipse(...);

次のようにする必要があります。

Graphics graphics=p.CreateGraphics();
...
graphics.FillEllipse(...);
graphics.FillEllipse(...);
graphics.FillEllipse(...);
于 2013-10-12T23:48:36.333 に答える