如何从旧图纸中清除面板 [英] How do I clear a panel from old drawing

查看:74
本文介绍了如何从旧图纸中清除面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个菜单项清除",该菜单项应清除所有图形中的面板.
仅此面板行中没有控件.

我认为从旧图纸上清除面板应该很容易,但是它
不是
我已经尝试过使用此代码
graphics.Clear(drawingBox1.BackColor);
但是清除后旧的图纸会退回.

因此,如何删除旧图形并在开始时具有面板原样
该程序
我的项目的链接:

[edit]链接/网址已删除-请发布代码,而不是url/link [/edit]



I have a menu item Clear which should clear the panel from all drawing.
There is no controls existing in this Panel only lines.

I thought it should be easy to clear the Panel from old drawings but it
isn''t
I have tried with this code
graphics.Clear(drawingBox1.BackColor);
but the old drawing reback after clearing .

So how can I remove the old drawing and have the Panel as it is when I start
the program
link of my project :

[edit]link/url removed - Please post code instead of url/link[/edit]

推荐答案

我希望您不使用PictureBox其他用于托管图形的特殊控件.

您需要立即在控件中绘制(例如PanelForm).您需要处理事件Paint或重写方法OnPaint,使用事件参数中提供的Graphics实例绘制数据.修改数据后,请调用Control.Invalidate.

即使需要保存位图,也不应将位图用于屏幕演示.取而代之的是,像这样提取渲染方法:void Render(System.Drawing.Graphics graphics)并从PaintOnPaint调用此方法.当需要将当前图形保存在位图(文件或其他内容)中时,请使用Render方法创建一个位图并在其上指向.
这是清理"或更改渲染图形的方法.您的渲染方法取决于一些数据.如果数据实例显示不呈现任何内容的方法,则不会呈现任何内容.您只需要更改数据并等待另一个渲染事件WM_PAINT.如果将控件的一部分最小化或用其他窗口遮罩并再次显示它,则会触发该事件.

您如何以编程方式触发它?通过调用Control.Invalidate,就没有别的了.您也可以使用参数(矩形或区域)调用Invalidate以通过仅在场景无效时请求一部分来提高性能.顺便说一下,这就是任何一种动画的实现方式.

—SA
I hope you''re not using PictureBox is some other special control to host graphics.

You need to draw immediately in your control (a Panel or a Form, for example). You need to handle the event Paint or override the method OnPaint, use the instance of Graphics supplied in event arguments to draw our your data. When your data is modified, call Control.Invalidate.

Even if you need to save a bitmap, you should not use the bitmap for screen presentation. Instead, abstract out the rendering method like this: void Render(System.Drawing.Graphics graphics) and call this method from Paint or OnPaint. When you need to save your current graphics in the bitmap (file or something), create a bitmap and point on it using your Render method.

Here is how you "clean" or change rendered graphics. You rendering method depends of some data. If the instance of data shows the method that nothing is to be rendered, nothing will be. You only need to change your data and wait for another rendering event WM_PAINT. It will be triggered if you minimize or mask part of the control with other window and show it again.

How do you trigger it programmatically? By calling Control.Invalidate, nothing else. You can also call Invalidate with parameters (Rectangle or Region) to improve performance by requesting only a part if the scene to be invalidated. This is how any kind of animation can be implemented, by the way.

—SA


我不知道是否有人会下载该文件,我确定我不会...

首先如何绘制线条?
I don''t know if anyone will download that file, I know for sure I won''t...

How are you drawing the lines in the first place?


这篇关于如何从旧图纸中清除面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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