I have to do an EtchaSketch program for my assignment. So far I have this code:
public partial class Form1 : Form
int x = 50, y = 50; // starting position
int x1 = 50, y1 = 50;
private void Form1_Load(object sender, EventArgs e)
bm = new Bitmap(this.Width, this.Height); // create a form-size bitmap
Graphics g = Graphics.FromImage(bm); // get a graphic object for the bitmap
g.FillEllipse(Brushes.Blue, x, y, 20, 20); // put a circle in the bitmap
this.BackgroundImage = bm; // use the bitmap as the form background
private void Form1_Paint(object sender, PaintEventArgs e)
Graphics h = e.Graphics; // get a graphic object for the bitmap
h.FillEllipse(Brushes.Blue, x1, y1, 20, 20);
You need to build up a list of the points that the circle as been to. Then in your Paint event handler, rather than just drawing the ellipse at x1, y1, you loop around all of the points drawing an ellipse at each....
// class members
private List<Point> _points = new List<Point>();
private Int32 _x = 50;
private Int32 _y = 50;
// paint handler
Graphics graphics = e.Graphics;
foreach (Point point in _points)
graphics.FillEllipse(Brushes.Blue, point.X, point.Y, 20, 20)
// in your process command...
if (input == "Down")
_y += 10;
// add the new point to the list
_points.Add(new Point(_x, _y);
// ... as before
You can now also easily implement a [Shake] button by simply calling:
and then refreshing....
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......