Как очистить picturebox c

от admin

Очистка PictureBox

Возможна ли очистка PictureBox, и, если да, то как она производится. С загрузкой изображения все более или менее понятно:

Но как же очистить PictureBox? Не вставить туда чистый белый рисунок, а именно очистить?

Если вдруг это не срабатывает, то есть такой вариант:

BlackWitcher's user avatar

Дизайн сайта / логотип © 2023 Stack Exchange Inc; пользовательские материалы лицензированы в соответствии с CC BY-SA . rev 2023.3.11.43304

Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.

How To clear PictureBox?

Member Avatar

can be something like below, check the attached project too :

Form1.cs :

stick a public method on Form2 to clear the picture box:

Then call the public method on Form2 from Form1.

sknake your obviously more pro than I but this could work out as well, right? =]

Not really. That frees the picture box. He asked how to hide it, not destroy it. The picture box will be unavailable after you dispose it.

All 14 Replies

Member Avatar

Hi can anyone tell me how can i do this.

Member Avatar

Member Avatar

can be something like below, check the attached project too :

Member Avatar

sknake your obviously more pro than I but this could work out as well, right? =]

Member Avatar

sorry my internet was laggy and it didnt go as fast so i pressed submit twice, i don’t know how to delete this post so srry

Member Avatar

sorry if this is double post but try this as well:

to make it go »away» or inivisble

and this to make it visible again ;D

Try it, but I know the post above this one works =]
the one with dispose() unless it just deletes it ;o

Member Avatar

Thank you all for your replies.
well i have one picturebox on form1 and another on form2, and i want to open both picturebox on form one on top and bottom panel respectively. And want to clear both picturebox simultaneosly on button click.
but the code you gave to me only valid and clear one picturebox, which is on form1. it is not applicable when form2’s picturebox also open in form1.
Can you please help me in this. pretty:

Clear image on picturebox

How can I clear draw image on picturebox? The following doesn’t help me:

EDIT

13 Answers 13

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:

Читать:
Как настроить резервное копирование на яндекс диск

As others have said, setting the Image property to null 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:

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.

Adnan Mohib's user avatar

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.

Очистка C # PictureBox и правильный масштаб

Я пытаюсь очистить PictureBox в своем приложении Windows Form перед размещением изображения после его интерполяции. Я искал похожие ситуации, но что-то вроде:

Не работают ни в каком сочетании. Я использовал этот метод, чтобы открыть изображение и поместить его на PictureBox :

После этого изображение интерполируется с помощью HighQualityBicubic , но результат помещается поверх исходного изображения. Я использовал свойство Zoom для PictureBox , поэтому оно не обрезает изображение и не закрывает остальную часть формы.

Есть ли способ удалить исходное изображение и увеличить результат в коробке?

Метод интерполяции (виноватая часть кода): void bicubic (int newHeight, int newWidth) <

2 ответа

Вы должны создать изображение без заданного размера. В вашем коде вы создаете новое изображение с исходным размером изображения

Это может решить вашу проблему

PictureBox.SizeMode = PictureBoxSizeMode.StretchImage растянет изображение для вас.

Если вам нужны другие свойства изменения размера, просто прокрутите список PictureBoxSizeMode .

Что касается переназначения, достаточно установить для свойства Image свойства Image значение null .

Похожие статьи