图片框重新加载后丢失绘图 [英] Picture box lose drawing after reloading

查看:89
本文介绍了图片框重新加载后丢失绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我目前正在使用PictureBox,并且遇到一个问题.
首先,我在PictureBox上绘制了一个椭圆,它在图片框上绘制得很好.
但是,当我最小化窗体并再次重新加载它时,在PictureBox上绘制的椭圆将使bin消失.
任何人都可以建议针对此问题的补救措施...
谢谢……..
问候,
Pritesh Patel

Hello friends,
I currently working with PictureBox and facing one problem.
First, I have drawn one ellipse on the PictureBox.It draws nicely on the picture box.
But when I minimizing the form and reload it again then the ellipse drawn on PictureBox have bin disappear.
Any one can suggest remedy for this problem…
Thanks……..
Regards,
Pritesh Patel

推荐答案

您忘了告诉我们您在使用什么. WPF? Windows窗体?

如果使用Windows窗体,则解决方案可能非常简单:您已绘制了一些内容,然后将窗体最小化.还原后,将告知所有控件重新绘制其内容,而旧内容将丢失.您必须简单地重写控件的OnPaint()方法,该方法在每次控件需要重绘其内容时都会调用.将您自己的绘图代码插入到重写的方法中,一切将保持应有的状态.
You forgot to tell us what you are using. WPF? Windows Forms?

If it''s Windows Forms, then the solution may be quite easy: You have drawn something and then minimize the form. When it is restored, all controls are told to redraw their contents and the old content is lost. You must simply override the controls OnPaint() method, which is called every time the control needs to redraw its content. Insert your own drawing code into the overridden method and everything will be as it should be,


做两件事:1)不要在图片框中绘制; 2)直接以CPD1802提供的方式呈现在某些控件上;使用覆盖的Control.OnPaint或事件Paint,使用事件参数中的Graphics对象.另外,最好使用双缓冲来避免闪烁.

要更改图形,请更改渲染中使用的数据并使用Control.Invalidate.为了提高性能,请将Invalidate与参数(矩形"或区域")一起使用,该参数可使场景的仅一部分无效.

图片盒在这种情况下是完全多余的,其目的有所不同.保留一些静态图片是很好的.如果要绘制它,可以,但是它是多余的,因为您可以在没有中间人的情况下绘制任何控件:更少的编码,内存消耗和更好的性能.

—SA
Do two things: 1) don''t draw in picture box; 2) render directly on some control, the way CPD1802 offered; use overridden Control.OnPaint or event Paint, use Graphics object from the event argument. Also, it''s good to use double buffering to avoid flicker.

To change graphics, change data used in rendering and use Control.Invalidate. To improve performance, use Invalidate with parameter (Rectangle or Region) which allows to invalidate just a part of the scene.

Picture box is completely redundant in this case, it''s purpose is different. It''s good to hold some static picture. If you want to draw in it, you can, but it is redundant as you can draw in any control without the middleman: less coding, memory consumption and better performance.

—SA


这篇关于图片框重新加载后丢失绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆