I've looked everywhere for double buffering of panels, but it all uses too confusing terms form me. I am graphing biorhythms and want to have a move function to slowly shift forward the biorhythms. However, it flashes alot so I need to figure out how to stop that. I tried to thread it, but to no avail, as threading still caused the flickering.
The following goes inside a timer: You can skip to the bottom to see where it draws the graphics. Basically, it refreshes, calculates, and plots the points.
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));
}