日期:2014-05-18 浏览次数:21033 次
using System; using System.Windows.Forms; using System.Drawing; using System.Threading; namespace 多线程带参数 { class Form1 : Form { private PictureBox pic; Graphics g; private int Bit_X,Loca; Bitmap bit; public Form1() { Initialize(); } private void Initialize() { pic = new PictureBox(); pic.Size = new Size(32, 48); pic.Location = new Point(0,0); g = pic.CreateGraphics(); this.SuspendLayout(); this.Controls.Add(pic); this.Size = new Size(500, 280); this.StartPosition = FormStartPosition.CenterScreen; this.ResumeLayout(); bit = new Bitmap("MAN.png"); Loca=Bit_X = 0; Thread thread1 = new Thread(new ThreadStart(ManMove)); thread1.IsBackground = true; thread1.Start(); CheckForIllegalCrossThreadCalls = false; } private void ManMove() { while (pic.Location.X < 500 - 32) { //bit.RotateFlip(RotateFlipType.Rotate90FlipY); Rectangle rect = new Rectangle(Bit_X, 96, 32, 48); Rectangle rectLoca=new Rectangle(0, 0, 32, 48); g.DrawImage(bit, rectLoca, rect, GraphicsUnit.Pixel); Thread.Sleep(5000); // Bit_X += 32; if (Bit_X >= 192) Bit_X = 0; // g.Clear(pic.BackColor); // pic.Location =new Point(Loca+=5,0); } MessageBox.Show("Exit"); } } }