using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace d3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.Image = Image.FromFile("C:\\Users\\ocean\\Desktop\\deneme.png");
pictureBox1.Location = new Point(0, 0);
pictureBox2.Image = Image.FromFile("C:\\Users\\ocean\\Desktop\\pul1.png");
}
protected override void OnMouseClick(MouseEventArgs e)
{
Graphics theGraphics = Graphics.FromHwnd(this.Handle);
for (int i = 0; i < 200; i += 5)
{
pictureBox2.Location = new Point(i, 100);
theGraphics.Flush();
System.Threading.Thread.Sleep(50);
pictureBox2.Invalidate();
}
}
}
}
이 코드에서 picturebox2는 괜찮 으면 이동하지만 이전 위치 이미지는 계속 루프가 끝납니다. 루프가 완료되면 이전 부품이 지워집니다. 나는 단지 pictureBox1로 이동하려는 루프 안의 이전 그림을 원하지 않습니다. 임 C#에서 새로운 그래서 제발 도와주세요 :) J2ME에서 나는 flushgraphics를 사용하고 있었지만 여기서 시도하고 작동하지 않았다. 당신이 예제를 줄 수 있다면 나는 행복 할 것이다.다른 이미지로 이미지 이동
대신, Thread.sleep를 가진 for 루프에서이 작업을 수행 이미지를 5 개 픽셀마다 이동 타이머로하지 않는다 50ms 후 정지합니다. 이렇게하면 변경 내용이 화면에 제대로 표시됩니다. – box86rowh
이 코드는 폼의 PaintBackground 메서드를 실행할 수 없으므로 픽셀을 바꿔야합니다.이런 루핑은 결코 문제가되지 않습니다. 메시지 루프가 실행되지 않으면 물건이 제대로 작동하지 않습니다. 타이머 대신 this.Update()가 반창고입니다. –