I am doing a picture in my project and I want to clear that picture from the picture box without deleting the other drawn picture when a command button is pressed .
any help

Dani AI

Generated

A short, practical explanation and three workable patterns for ’s problem.

When multiple pictures or shapes are drawn into one PictureBox they become a single composite bitmap. That means there is no built‑in “erase just one pasted image” operation — clearing or removing one element requires either restoring pixels from a saved copy, keeping each element in its own layer, or rebuilding the bitmap from a stored scene description. Several replies here point to ways of wiping the whole control; those clear-everything approaches (as suggested by , , and ) are fine when the entire image should go, but won’t remove a single overlay without affecting the rest.

Three practical approaches (pick the one that fits the project):

  • Separate layers: put each image that must be independently removable into its own PictureBox/Image control stacked over the background. Hiding or replacing just that control removes the image without touching others. Best for a small number of independent images.

  • Scene model + redraw: keep a small data structure (collection/array) describing every drawable item (type, image filename or handle, coordinates, z-order). To remove an item, delete it from the list, clear the canvas, and redraw everything from the list. This is the most robust and scales well for many objects or interactive editors.

  • Snapshot/restore: before drawing the removable image, capture the underlying pixels into an off‑screen buffer. To erase the overlay, copy the saved rectangle back into the live control. This is useful for a single, localized undo but requires exact coordinate mapping and a true bitmap copy (simple variable assignment often just copies a reference rather than pixels).

Practical tips/cautions: ensure the drawing surface is set to persist (auto‑redraw style options) so snapshots are accurate; keep scale/units consistent when copying regions; copying via a real off‑screen bitmap is safer than relying on object references; for many edits prefer the scene+redraw pattern for clarity and maintainability. ’s dummy‑picture idea already demonstrates the snapshot pattern; the scene/redraw or separate‑controls approaches are the cleanest long‑term solutions.

Recommended Answers

All 7 Replies

Hi,

Just use:

Picture1.Cls

Regards
Veena

sir, the code
picture1.cls
will clear the entire picutre box what I want is to clear only one picture from the existing pictures inside the picture box.

picture1.Picture = New StdPicture

;)

Hi,

Keep a Dummy Picture Box on the Form Say DPict

use this Code:
DPict.Picture = LoadPicture 'Clear Pict
Picture1.PaintPicture DPict.Image, 2000, 0, 2000, 1000
Picture1.Refresh

This Clears the Picture stored in Area :
2000, 0
And Width=2000, Height 1000


Regards
Veena

image1.visible= False
image1.picture= Nothing

try a simpler approach

image1.picture=nothing

  • **picture1.open=loadpicture("m.jpg")
  • picture1.cls
  • msgbox"r u sure want to delete"
  • picture1.refresh**
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.