Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
My image didnot move smoothly, please help me.
k
Nov 7 2008 9:40 AM
5.4k
Reply
I try to make small image movable, but it didnot move smoothly. Anyone can help me?
Thanks in advance.
My project:
http://www.adrive.com/public/cb65f291603e8...2ce7200841.html
namespace ImageMoving
{
public class car
{
public Image pic;
public int x;
public int y;
public car()
{
pic = Image.FromFile("myimage.jpg");
}
}
public partial class Form1 : Form
{
Timer MyTimer = new Timer();
car MyCar = new car();
Image imgbg;
public Form1()
{
InitializeComponent();
imgbg = Image.FromFile("background.jpg");
MyCar.x = 0;
MyCar.y = 0;
MyTimer.Interval = 20;
MyTimer.Start();
MyTimer.Tick += new EventHandler(MyTimer_Tick);
}
void MyTimer_Tick(object sender, EventArgs e)
{
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
Image imgBuffer = new Bitmap(this.Width, this.Height);
Graphics grBuffer = Graphics.FromImage(imgBuffer);
grBuffer.DrawImage(imgbg, 0, 0);
using (grBuffer)
{
grBuffer.DrawImage(MyCar.pic, MyCar.x, MyCar.y);
MyCar.x += 5;
e.Graphics.DrawImage(imgBuffer, 0, 0);
}
imgBuffer.Dispose();
}
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Sphere in C# without DirectX mapped by a texure jpg or bmp file
DrawImage Artifacts