No I meant overriding the OnPaint method of the form (but that shouldn't make a difference). I made a simple text which work fine for me (when the image is very big it slows down). Probably it helps you:
public class Form1 : System.Windows.Forms.Form
{
private Point _curPos = new Point(0, 0);
private Image _image;
public Form1()
{
base.KeyPress += new KeyPressEventHandler(Form1\_KeyPress);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
\_image = new Bitmap("C:\\\\test2.jpg");
}
private void Form1\_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case 'w': \_curPos.Y -= 5; break;
case 's': \_curPos.Y += 5; break;
case 'a': \_curPos.X -= 5; break;
case 'd': \_curPos.X += 5; break;
}
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
e.Graphics.DrawImageUnscaled(\_image, \_curPos);
}
}
Note that I'm calling the Invalidate method instead of Refresh. This is always better because the Refresh will repaint the form immediatly while Invalidate will wait until there is time to do so. If you have much more other things on your form it would also be a good idea to give a Rectangle into the form which specifies which particular region should be repainted.