c# PictureBox.update以后gif为什么只显示一帧呢??
我在C#winform中加入了一个鼠标单击事件,点击后事件PictureBox.visible=true;后面有一个连接远程数据库的事件,但是图片加载不出来,我使用了Pi...
我在C# winform中加入了一个鼠标单击事件,点击后事件PictureBox.visible=true;
后面有一个连接远程数据库的事件,但是图片加载不出来,我使用了 PictureBox.update()方法读取图片,但是只读到了gif的一帧,请教原因及解决方法 展开
后面有一个连接远程数据库的事件,但是图片加载不出来,我使用了 PictureBox.update()方法读取图片,但是只读到了gif的一帧,请教原因及解决方法 展开
展开全部
PictureBox加载之后是静态的,以位图显示
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
winform的picturebox是不能显示gif的帧的....(ps:烂控件一个)
以下是让picturebox画出gif的源码
给窗体加一个 backgroundWorker
void Form1_Load(object sender, EventArgs e)
{
this.backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
this.backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
this.button1.Click += new EventHandler(button1_Click);
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
//string reportPath = @"C:\1.ani";
//int cur = LoadCursorFromFile(reportPath);
//SetSystemCursor(cur, 32512);
int cur = LoadCursorFromFile(@"C:\ScreenCapture.ani");
SetSystemCursor(cur, 32512);
//Cursor.Current = new Cursor(@"C:\aa.ani");
//this.Cursor = new Cursor(@"C:\aa.ani");
fd = new FrameDimension(image.FrameDimensionsList[0]);
DrawingNum = image.GetFrameCount(fd);
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
int cur = LoadCursorFromFile(@"C:WINDOWS\Cursorsarrow_m.cur");
SetSystemCursor(cur, 32512);
//backgroundWorker1.ProgressChanged -=new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
//if (backgroundWorker1.IsBusy) backgroundWorker1.CancelAsync();
//fd = null;
//image = null;
}
FrameDimension fd;
Image image = Image.FromFile(@"C:\loading.gif");
int DrawingNum = 0;
bool dowork = false;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
dowork = !dowork;
if (dowork) backgroundWorker1.RunWorkerAsync();
else backgroundWorker1.CancelAsync();
}
void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.Refresh();
image.SelectActiveFrame(fd, e.ProgressPercentage);
this.CreateGraphics().DrawImage(image, MousePosition.X - this.Location.X +8 , MousePosition.Y - this.Location.Y - 8);
}
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (dowork)
{
for (int i = 0; i < DrawingNum; i++)
{
Thread.Sleep(100);
backgroundWorker1.ReportProgress(i);
}
}
}
以下是让picturebox画出gif的源码
给窗体加一个 backgroundWorker
void Form1_Load(object sender, EventArgs e)
{
this.backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
this.backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
this.button1.Click += new EventHandler(button1_Click);
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
//string reportPath = @"C:\1.ani";
//int cur = LoadCursorFromFile(reportPath);
//SetSystemCursor(cur, 32512);
int cur = LoadCursorFromFile(@"C:\ScreenCapture.ani");
SetSystemCursor(cur, 32512);
//Cursor.Current = new Cursor(@"C:\aa.ani");
//this.Cursor = new Cursor(@"C:\aa.ani");
fd = new FrameDimension(image.FrameDimensionsList[0]);
DrawingNum = image.GetFrameCount(fd);
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
int cur = LoadCursorFromFile(@"C:WINDOWS\Cursorsarrow_m.cur");
SetSystemCursor(cur, 32512);
//backgroundWorker1.ProgressChanged -=new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
//if (backgroundWorker1.IsBusy) backgroundWorker1.CancelAsync();
//fd = null;
//image = null;
}
FrameDimension fd;
Image image = Image.FromFile(@"C:\loading.gif");
int DrawingNum = 0;
bool dowork = false;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
dowork = !dowork;
if (dowork) backgroundWorker1.RunWorkerAsync();
else backgroundWorker1.CancelAsync();
}
void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.Refresh();
image.SelectActiveFrame(fd, e.ProgressPercentage);
this.CreateGraphics().DrawImage(image, MousePosition.X - this.Location.X +8 , MousePosition.Y - this.Location.Y - 8);
}
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (dowork)
{
for (int i = 0; i < DrawingNum; i++)
{
Thread.Sleep(100);
backgroundWorker1.ReportProgress(i);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询