Hallo,
was mache ich hier falsch. Ich möchte eine Zeitreihe, die von einem Timer
geliefert wird in ein Panel zeichnen.
Das Bild flackert ziemlich stark.
Die paar Punkte (Größenordnung 255) sollten doch ohne Flackern gezeichnet werden.
xBegin bezeichnet meinen Ausschnitt in der Datenreihe
points.
Sollte ich grundsätzlich am Ende das Dispose einfügen?
Vielen Dank für Hinweise,
Steffen
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| public Form1() { InitializeComponent(); this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); this.timer1.Interval = 20;
} |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
| private void panel1_Paint(object sender, PaintEventArgs e) { Panel p = (Panel)sender; Graphics g = e.Graphics; int pCount = points.Count;
int PanelHeight = p.Height; int PanelWidth = p.Width; int ClientHeight = p.ClientRectangle.Height; int ClientWidth = p.ClientRectangle.Width; float ClipHeight = g.ClipBounds.Height; float ClipWidth = g.ClipBounds.Width; int eClipLeft = e.ClipRectangle.Left; int eClipRight = e.ClipRectangle.Right; Point asPosition = p.AutoScrollPosition;
int xBegin; int xEnd; xBegin = - asPosition.X + 1; xEnd = eClipRight > pCount ? pCount : eClipRight;
GraphicsPath gp = new GraphicsPath(); for (int x = 1; x < xEnd; x++) { gp.AddLine(x - 1, points[xBegin - 1] * yScale * mAmpScale, x, points[xBegin] * yScale * mAmpScale); if ((xBegin % 100) == 0) { g.DrawString(xBegin.ToString(), pFont, bECG, (float)x, 10.0f); } xBegin++; } g.DrawPath(pECG, gp); p.AutoScrollMinSize = new Size(pCount , PanelHeight);
if (bScroll) { p.AutoScrollPosition = new Point(pCount - p.Width, p.AutoScrollPosition.Y); } } |