My goal is to be able to draw just one rectangle (filled color) on the form and make it move.
So, first, to draw a filled rectangle on the form, this is what I do:
public class Form1 : Form
Graphics g = this.CreateGraphics();
SolidBrush sb = new SolidBrush(Brushes.Red);
g.FillRectangle(sb, this.Location.X, this.Location.Y, 10, 10);
private void Form1_Paint(object sender, PaintEventArgs e)
So, I know if I put the Graphics creation code inside the Paint event method, then it will work.
However, I want to have a generic way so that I can set the location of the rectangle dynamically, and then call Paint manually, because next thing I want to be able to make the rectangle move (like left to right animation, 10 pixels every 2 seconds).
So, what I am trying to get is, like this:
1. set location
3. repeat #1
Can somebody please enlighten me with relationship between drawing and painting? which one come first, the procedure, etc?