如何从图片框中删除矩形graphis [英] How to erase rectangle graphis from picture box

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

问题描述

你好



如何从图片框中删除矩形图形,我可以使用以下代码绘制矩形图形:



Dim g As System.Drawing.Graphics

Dim cyan As New SolidBrush(Color.Yellow)

Dim rect As New Rectangle(x1, y1,15,15)

g.FillRectangle(青色,矩形)



是否可以删除我绘制的矩形图形,请告诉我怎么做。



谢谢。

Hello

how to remove the rectangle graphics from picture box, I am able to draw a rectangle graphics using this code:

Dim g As System.Drawing.Graphics
Dim cyan As New SolidBrush(Color.Yellow)
Dim rect As New Rectangle(x1, y1, 15, 15)
g.FillRectangle(cyan, rect)

Is it possible to remove this rectangle graphics i had draw, Please tell me how to do so.

Thanks.

推荐答案

你只需在PictureBox上调用Invalidate控制而不是在上面绘制你的盒子。



这会强制控件重绘自己没有你画的框。
You simply call Invalidate on the PictureBox control and NOT draw your box on it.

This will force the control to redraw itself without the box you drew.


使用你的代码,你根本不应该使用 PictureBox - 它没有对你有用,什么都没有,只会增加一些痛苦......让我们说,在颈部和窃取你的一些开发时间。该怎么做?更简单的东西。请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

画一个矩形C# [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

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

如何加速我的vb.net应用程序? [ ^ ]。



是的,你需要有一些数据模型可能包含,比如说,一个名为clear的布尔标志。如果它清除,就​​不要做任何渲染。当您调用 Control.Invalidate()时,您的图形将被刷新,并且您的渲染方法将被调用而不是绘制任何东西。



-SA
With your code, you should not use PictureBox at all — it does nothing useful for you, nothing at all, only adds some pain in the… let's say, in the neck and steals some of your development time. What to do instead? Something a lot more simple. Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
How to speed up my vb.net application?[^].

And yes, you need to have some data model which may include, say, a Boolean flag named "clear". If it's "clear", just don't do any rendering. When you call Control.Invalidate(), your graphics will be refreshed, and your rendering method will be called not drawing anything.

—SA


这篇关于如何从图片框中删除矩形graphis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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