C# pictureBox里拖动图片后,然后我在画直线,图片又回到拖动前的地方 C# pictureBox里拖动图片后,然后我在画直线,图片又回到拖动前的地方我在画直线的代码里,使用了this.pictureBox1.Invalidata();我知道是这个原因造成的,但这个又不能去掉,请问怎么办? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面是我拖动图片用到的代码: private void MyReDrawTest(Point offset) { Image srcBitmap = this.pictureBox1.Image; if (srcBitmap == null) return; BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; BufferedGraphics myBuffer = currentContext.Allocate(this.pictureBox1.CreateGraphics(), this.pictureBox1.DisplayRectangle); myBuffer.Graphics.Clear(this.pictureBox1.BackColor); myBuffer.Graphics.DrawImage(srcBitmap, offset); myBuffer.Render(this.pictureBox1.CreateGraphics()); myBuffer.Dispose(); } 1、将BufferedGraphicsContext 、BufferedGraphics 为全局变量,在构造时赋值2、绑定pictureBox重绘事件3、在重绘时将图像缓存区图像写入GraphicsCode BufferedGraphicsContext currentContext; BufferedGraphics myBuffer; Graphics g; bool userPaint; public Form1() { InitializeComponent(); currentContext = BufferedGraphicsManager.Current; g = pictureBox1.CreateGraphics(); myBuffer = currentContext.Allocate(g, this.pictureBox1.DisplayRectangle); userPaint = false; pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (userPaint) myBuffer.Render(e.Graphics); } private void MyReDrawTest(Point offset) { Image srcBitmap = this.pictureBox1.Image; if (srcBitmap == null) return; myBuffer.Graphics.Clear(this.pictureBox1.BackColor); myBuffer.Graphics.DrawImage(srcBitmap, offset); myBuffer.Render(this.pictureBox1.CreateGraphics()); if (!userPaint) userPaint = true; } 求教如何打印报表呢 the given key was not present in the dictionary Form.Size与CreateGraphics webbrowser 抓数据的遇到新问题了. C# 修改密码 代码 怎么在developer 与 tester 环境类型将切换?? 小弟今天面试,大侠帮看看吧 文本框内容逐行合并 --菜鸟求大神帮助~~ ~ 关于TlbImp工具使用问题 请问这是个什么东东问题?(只有这么多分了。。) 新手菜鸟问题 写出一条Sql语句
private void MyReDrawTest(Point offset)
{
Image srcBitmap = this.pictureBox1.Image;
if (srcBitmap == null)
return; BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; BufferedGraphics myBuffer = currentContext.Allocate(this.pictureBox1.CreateGraphics(), this.pictureBox1.DisplayRectangle); myBuffer.Graphics.Clear(this.pictureBox1.BackColor); myBuffer.Graphics.DrawImage(srcBitmap, offset); myBuffer.Render(this.pictureBox1.CreateGraphics()); myBuffer.Dispose();
}
2、绑定pictureBox重绘事件
3、在重绘时将图像缓存区图像写入Graphics
Code BufferedGraphicsContext currentContext;
BufferedGraphics myBuffer;
Graphics g;
bool userPaint; public Form1()
{
InitializeComponent();
currentContext = BufferedGraphicsManager.Current;
g = pictureBox1.CreateGraphics();
myBuffer = currentContext.Allocate(g, this.pictureBox1.DisplayRectangle);
userPaint = false;
pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
} private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (userPaint)
myBuffer.Render(e.Graphics);
} private void MyReDrawTest(Point offset)
{ Image srcBitmap = this.pictureBox1.Image;
if (srcBitmap == null)
return; myBuffer.Graphics.Clear(this.pictureBox1.BackColor); myBuffer.Graphics.DrawImage(srcBitmap, offset); myBuffer.Render(this.pictureBox1.CreateGraphics()); if (!userPaint)
userPaint = true;
}