用图形方法绘制的线条有多清晰? [英] How clear lines that drawn with graphics method?

查看:149
本文介绍了用图形方法绘制的线条有多清晰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要清除用图形方法绘制的窗体中的所有线条。

这是代码:

Hi,I want clear all line in windows form that drawn with graphic method.
Here this is the code :

Graphics^ pg = CreateGraphics();
Pen^ pen1 = gcnew Pen(Color::Red);
pg->DrawLine(pen1, 100, 100, 200, 200);





我尝试用Graphic.clear()来做但不成功。

请帮助我!



I try do it by Graphic.clear() but it wasn't successful.
Please help me!

推荐答案

首先,您必须在事件处理程序中执行所有图形渲染 Paint ,或重写方法 Control.Paint 。当控件或其部件无效时,将完成对处理程序的实际调用。它发生在不同的情况下,但您可以明确地对整个场景或其部分进行反映,以反映数据的最新变化: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate%28v=vs .110%29.aspx [ ^ ]。



请查看我过去的答案:

Paint有什么好玩的方法? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



让我们说,你有一个控件类的布尔成员,比如 makeEmpty 。如果你在你的处理程序中使用它,你可以编写 if(makeEmpty)doSomeRendering(graphics); 然后你可以控制渲染(或部分渲染)是否完成下次失效后。要清除视图,您可以将其指定为false并调用 Invalidate ,然后渲染将在没有您的行的情况下刷新。



-SA
First of all, you have to do all graphics rendering in your handler of the event Paint, or overridden method Control.Paint. The actual call to your handler is done when the control or its part is invalidated. It happens in different situation, but you can explicitly do it, for the whole scene or its part, to reflect last changes in your data: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate%28v=vs.110%29.aspx[^].

Please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

Let's say, you have a Boolean member of your control's class, such as makeEmpty. If you use it in your handler, you can wrote if (makeEmpty) doSomeRendering(graphics); then you control if you rendering (or part of your rendering) is done or not after next invalidation. To "clear" the view, you can assign it to false and call Invalidate, then rendering will be refreshed without your lines.

—SA


您可以使用背景颜色调用Graphics.Clear或调用this.Invalidate()方法将其删除。
You can call Graphics.Clear with background color or call this.Invalidate() method to erase it.


这篇关于用图形方法绘制的线条有多清晰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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