图片框上的清晰图像
如何清除picturebox上的绘制图像? 以下内容对我没有帮助:
pictbox.Image = null;
pictbox.Invalidate();
请帮忙。
编辑
private void pictbox_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
vl.Draw(g, ref tran.realListForInsert);
}
public void Draw(Graphics g, ref List<double> arr)
{
g.DrawRectangle(new Pen(Brushes.Red, 3), nodeArr[Convert.ToInt32(templstName)].pict.Location.X, nodeArr[Convert.ToInt32(templstName)].pict.Location.Y, 25, 25);
g.DrawRectangle(new Pen(Brushes.Green, 3), nodeArr[Convert.ToInt32(templstArgName)].pict.Location.X, nodeArr[Convert.ToInt32(templstArgName)].pict.Location.Y, 25, 25);
nodeArr[Convert.ToInt32(templstName)].text.Text = arr[Convert.ToInt32(templstArgName)].ToString();
arr[Convert.ToInt32(templstName)] = arr[Convert.ToInt32(templstArgName)];
}
How can I clear draw image on picturebox?
The following doesn't help me:
pictbox.Image = null;
pictbox.Invalidate();
Please help.
EDIT
private void pictbox_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
vl.Draw(g, ref tran.realListForInsert);
}
public void Draw(Graphics g, ref List<double> arr)
{
g.DrawRectangle(new Pen(Brushes.Red, 3), nodeArr[Convert.ToInt32(templstName)].pict.Location.X, nodeArr[Convert.ToInt32(templstName)].pict.Location.Y, 25, 25);
g.DrawRectangle(new Pen(Brushes.Green, 3), nodeArr[Convert.ToInt32(templstArgName)].pict.Location.X, nodeArr[Convert.ToInt32(templstArgName)].pict.Location.Y, 25, 25);
nodeArr[Convert.ToInt32(templstName)].text.Text = arr[Convert.ToInt32(templstArgName)].ToString();
arr[Convert.ToInt32(templstName)] = arr[Convert.ToInt32(templstArgName)];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
设置
Image
属性 为 null 就可以了。它将清除图片框中当前显示的任何图像。确保您编写的代码与如下所示完全相同:Setting the
Image
property to null will work just fine. It will clear whatever image is currently displayed in the picture box. Make sure that you've written the code exactly like this:正如其他人所说,将
Image
属性设置为null
应该可以。如果没有,则可能意味着您使用了 InitialImage 属性来显示您的图像。如果确实如此,请尝试将该属性设置为
null
:As others have said, setting the
Image
property tonull
should work.If it doesn't, it might mean that you used the InitialImage property to display your image. If that's indeed the case, try setting that property to
null
instead:您需要以下内容:
You need the following:
我假设您想清除通过 PictureBox 绘制的图像。
这可以通过 Bitmap 对象并使用 Graphics 对象来实现。你可能正在做类似的事情,
这就是你正在寻找的吗?
编辑
由于您使用的是绘制方法,这会导致每次都重新绘制,我建议您在表单级别设置一个标志,指示是否应该绘制 Picturebox
在您的绘制中只需使用
当您单击按钮时,将此属性设置为 false 应该没问题。
I assume you want to clear the Images drawn via PictureBox.
This you would be achieved via a Bitmap object and using Graphics object. you might be doing something like
Is this what you were looking out?
EDIT
Since you are using the paint method this would cause it to be redrawn every time, I would suggest you to set a flag at the formlevel indicating whether it should or not paint the Picturebox
In your paint just use
When you click the button set this property to false and you should be fine.
为了便于理解:
根据您实现目标的方式,请记住开发人员有责任处置不再使用或不再需要的所有内容。
这意味着:您随 pictureBox 创建的所有内容(即:图形、列表等)都将在不再需要时被丢弃。
例如:
假设您有一个图像文件加载到 PictureBox 中,并且您希望以某种方式删除该文件。
如果您没有正确从 PictureBox 中卸载图像文件;您将无法删除该文件,因为这可能会引发异常,表明该文件正在使用。
因此,您需要执行以下操作:
希望这对您有所帮助。
For the Sake of Understanding:
Depending on how you're approaching your objective(s), keep in mind that the developer is responsible to Dispose everything that is no longer being used or necessary.
This means: Everything you've created along with your pictureBox (i.e: Graphics, List; etc) shall be disposed whenever it is no longer necessary.
For Instance:
Let's say you have a Image File Loaded into your PictureBox, and you wish to somehow Delete that file.
If you don't unload the Image File from PictureBox correctly; you won't be able to delete the file, as this will likely throw an Exception saying that the file is being used.
Therefore you'd be required to do something like:
Hope this helps you out.
我也曾有过一个顽固的形象,它不会消失
通过将 Image 和 InitialImage 设置为 null。
要从图片框中永久删除图像,我必须使用下面的代码,
通过重复调用 Application.DoEvents() :
I've had a stubborn image too, that wouldn't go away
by setting the Image and InitialImage to null.
To remove the image from the pictureBox for good, I had to use the code below,
by calling Application.DoEvents() repeatedly:
我必须在 Image = null 之后添加 Refresh() 语句才能使事情正常工作。
I had to add a Refresh() statement after the Image = null to make things work.
就这么简单!
您可以使用按钮单击事件,
我将它与按钮属性名称一起使用:“btnClearImage”
Its so simple!
You can go with your button click event,
I used it with a button property Name: "btnClearImage"
我用这个方法来清除图片框中的图像。它可能会帮助某人
I used this method to clear the image from picturebox. It may help some one
你应该尝试一下。当您清除图形时,您必须选择颜色。 SystemColors.Control 是表单的本机颜色
You should try. When you clear your Graphics you must choose color. SystemColors.Control is native color of form
在c# winform应用程序中清除pictureBox
在c# winform应用程序中清除pictureBox的简单方法
clear pictureBox in c# winform Application
Simple way to clear pictureBox in c# winform Application