C# win编程,我想实现一张图片在窗体中平滑移动 80
我用timer实现变换坐标(x,y),非常的卡(或者说闪烁)。求大神指点,怎么实现,才不卡(闪烁)。...
我用timer实现变换坐标(x,y),非常的卡(或者说闪烁)。求大神指点,怎么实现,才不卡(闪烁)。
展开
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication73
{
public partial class Form1 : Form
{
Bitmap OrgBmp = null;
int PosX = 0;
Thread T = null;
delegate void DrawForm(Bitmap CacheBmp);
public Form1()
{
InitializeComponent();
OrgBmp = new Bitmap(this.Width, this.Height);
Graphics G = Graphics.FromImage(OrgBmp);
G.FillRectangle(new SolidBrush(this.BackColor), this.Bounds);
G.Dispose();
T = new Thread(new ThreadStart(Run));
T.IsBackground = true;
T.Start();
}
void Run()
{
Bitmap CacheBmp = null;
Graphics G = null;
try
{
while (true)
{
if (++PosX > this.Width)
PosX = 0;
CacheBmp = new Bitmap(OrgBmp);
G = Graphics.FromImage(CacheBmp);
G.DrawString("ABCDEFG12345", new Font("宋体", 10), Brushes.Green, new PointF(PosX, 0));
if (!this.IsDisposed && this.IsHandleCreated)
this.Invoke(new DrawForm(DoDrawForm), new Object[] { CacheBmp });
}
}
catch
{
}
finally
{
if (G != null)
G.Dispose();
if (CacheBmp != null)
{
CacheBmp.Dispose();
GC.Collect();
}
}
}
void DoDrawForm(Bitmap CacheBmp)
{
Graphics G = null;
try
{
G = this.CreateGraphics();
G.DrawImage(CacheBmp, new Point(0, 0));
}
finally
{
if (G != null)
G.Dispose();
GC.Collect();
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication73
{
public partial class Form1 : Form
{
Bitmap OrgBmp = null;
int PosX = 0;
Thread T = null;
delegate void DrawForm(Bitmap CacheBmp);
public Form1()
{
InitializeComponent();
OrgBmp = new Bitmap(this.Width, this.Height);
Graphics G = Graphics.FromImage(OrgBmp);
G.FillRectangle(new SolidBrush(this.BackColor), this.Bounds);
G.Dispose();
T = new Thread(new ThreadStart(Run));
T.IsBackground = true;
T.Start();
}
void Run()
{
Bitmap CacheBmp = null;
Graphics G = null;
try
{
while (true)
{
if (++PosX > this.Width)
PosX = 0;
CacheBmp = new Bitmap(OrgBmp);
G = Graphics.FromImage(CacheBmp);
G.DrawString("ABCDEFG12345", new Font("宋体", 10), Brushes.Green, new PointF(PosX, 0));
if (!this.IsDisposed && this.IsHandleCreated)
this.Invoke(new DrawForm(DoDrawForm), new Object[] { CacheBmp });
}
}
catch
{
}
finally
{
if (G != null)
G.Dispose();
if (CacheBmp != null)
{
CacheBmp.Dispose();
GC.Collect();
}
}
}
void DoDrawForm(Bitmap CacheBmp)
{
Graphics G = null;
try
{
G = this.CreateGraphics();
G.DrawImage(CacheBmp, new Point(0, 0));
}
finally
{
if (G != null)
G.Dispose();
GC.Collect();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
网上有类似的 你看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要么让图片跑的快一点,要么换的wpf
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用双缓存绘图
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用WinDows API 能实现你这个
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询