C#winform未响应问题
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;
using Test_Eight.Properties;
namespace Test_Eight
{
public partial class AutoPlay : Form
{
public AutoPlay()
{
InitializeComponent();
}
private Bitmap MyBitmap; //事件公用变量
//初始化
private void AutoPlay_Load(object sender, EventArgs e)
{
Bitmap SrcBitmap = new Bitmap(Resources._1); //把打开的图像赋给Bitmap变量
MyBitmap = new Bitmap(SrcBitmap, this.pictureBox_Show.Width, this.pictureBox_Show.Height);
this.pictureBox_Show.Image = MyBitmap; //在控件上显示图像
timer_Change.Enabled = true;
}
//对接
private void Joint()
{
try
{
int width = this.pictureBox_Show.Width;//图像宽度
int height = this.pictureBox_Show.Height;//图像高度
Graphics g = this.pictureBox_Show.CreateGraphics();
g.Clear(Color.Gray);
Bitmap bitmap = new Bitmap(width, height);
int x = 0;
while (x <= height / 2)
{
for (int i = 0; i <= width - 1; i++)
{
bitmap.SetPixel(i, x, MyBitmap.GetPixel(i, x));
}
for (int i = 0; i <= width - 1; i++)
{
bitmap.SetPixel(i, height - x - 1, MyBitmap.GetPixel(i, height - x - 1));
}
x++;
this.pictureBox_Show.Invalidate();
g.DrawImage(bitmap, 0, 0);
System.Threading.Thread.Sleep(1);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//中间拉伸
private void Middle_Stretch()
{
int width = this.pictureBox_Show.Width; //图像宽度
int height = this.pictureBox_Show.Height; //图像高度
Graphics g = this.pictureBox_Show.CreateGraphics(); //创建Graphics对象实例
g.Clear(Color.Gray); //初始为全灰色
for (int y = 0; y <= width / 2; y++) //两边拉伸显示
{
Rectangle DestRect = new Rectangle(width / 2 - y, 0, 2 * y, height);
Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
System.Threading.Thread.Sleep(1);
}
}
int Count = 0;
//切换图片
private void timer_Change_Tick(object sender, EventArgs e)
{
Count++;
switch (Count)
{
case 1: Joint(); break;
case 2: Middle_Stretch(); break;
default: break;
}
if (Count == 3)
{
Count = 0;
pictureBox_Show.Image = Resources._1;
}
}
}
}
protected override void OnClosing(CancelEventArgs e)
{
try
{
timer_Change.Enabled = false;
base.OnClosing(e);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}