i am trying to create slider movement graphics. The code explain better this.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace temp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private System.Drawing.Graphics g;
private System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.Black, 1F);
//timer for animation
private void Form1_Load(object sender, EventArgs e)
{
Timer a = new Timer();
a.Interval = 60;
a.Tick += new EventHandler(a_Tick);
a.Start();
}
void a_Tick(object sender, EventArgs e)
{
button1_Click(this, null);
}
//draws randomly generated point array.
int cnt = 0;
private void button1_Click(object sender, EventArgs e)
{
rAr();
g = pictureBox1.CreateGraphics();
g.Clear(Color.Violet);
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawCurve(pen1, points2);
cnt++;
}
Random r = new Random();
Point[] p = new Point[100];
Point[] points2 = new Point[100];
int c = 4;
//fills new random point array
private void rAr()
{
points2.CopyTo(p, 0);
int cc = 1;
for (int i = points2.Length - 1; i > 0; i--)
{
points2[i - 1] = new Point(100 - cc, p[i].Y);
cc++;
}
points2[99] = new Point(100, r.Next(1, 50));
}
}
}
this code works fine put the problem is that it takes to much cpu and automation is not very smooth. is there some other way to achieve same thing put with much less cpu. Thanks for replays