110,546
社区成员
发帖
与我相关
我的任务
分享
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); //默认启动双缓冲
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
haha = new Bitmap(panel1.Width, panel1.Height);
g = Graphics.FromImage(haha);
pang = panel1.CreateGraphics();
}
Graphics g;
int x = 0;
Image haha;
Graphics pang;//panel1
private void timer1_Tick(object sender, EventArgs e)
{
x += 3;
timer1.Interval = 1;
Invalidate();
Draw();
}
private void Draw()
{
using (Graphics g = Graphics.FromImage(haha))
{
g.Clear(Color.White);
g.DrawImage(Properties.Resources._2, -x, 100);
g.DrawImage(Properties.Resources._2, x, 100);
g.DrawImage(Properties.Resources._2, x, 0);
g.DrawImage(Properties.Resources._2, -x, -x);
g.Dispose();
}
}
protected override void OnPaint(PaintEventArgs e)
{
Draw();
pang.DrawImage(haha, Point.Empty);
}
}
}
Graphics g1 = Graphics.FromImage(Properties.Resources._2);
Image MyImage = new Bitmap(1024,768, g1);
Graphics g2 = this.CreateGraphics();
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, MyImage.Width, MyImage.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);