Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to delete a picture???

How to delete a picture???

Scheduled Pinned Locked Moved C#
helptutorialquestion
9 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CrazyDragon6384
    wrote on last edited by
    #1

    hi guys, I have a picBox and a list of pictures. These pictures are displayed in ordered by 2 button ( previous and next ) in the picBox. When clicking buttonDelete, I want to delete the picture which is being displayed in picBox at present and then,another pic is displayed in picBox. But,if any pictures were displayed in the past, it couldn't be deleted. (error: ... because it is being used by another process.) F1 - help me :). thanks !!! -- modified at 13:53 Monday 27th February, 2006

    M 1 Reply Last reply
    0
    • C CrazyDragon6384

      hi guys, I have a picBox and a list of pictures. These pictures are displayed in ordered by 2 button ( previous and next ) in the picBox. When clicking buttonDelete, I want to delete the picture which is being displayed in picBox at present and then,another pic is displayed in picBox. But,if any pictures were displayed in the past, it couldn't be deleted. (error: ... because it is being used by another process.) F1 - help me :). thanks !!! -- modified at 13:53 Monday 27th February, 2006

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! How are you trying to delete the image displayed in the PictureBox? To get an empty PictureBox you can simply assign null to the Image property. Regards, mav -- Black holes are the places where god divided by 0...

      C 1 Reply Last reply
      0
      • M mav northwind

        Hi! How are you trying to delete the image displayed in the PictureBox? To get an empty PictureBox you can simply assign null to the Image property. Regards, mav -- Black holes are the places where god divided by 0...

        C Offline
        C Offline
        CrazyDragon6384
        wrote on last edited by
        #3

        I only want to delete the picture displaying on PictureBox,and then the pictureBox will display next( or previous) picture in my list Picture. :) -- modified at 21:26 Monday 27th February, 2006

        M 1 Reply Last reply
        0
        • C CrazyDragon6384

          I only want to delete the picture displaying on PictureBox,and then the pictureBox will display next( or previous) picture in my list Picture. :) -- modified at 21:26 Monday 27th February, 2006

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          Still not sure what you really want. Are you trying to delete the file the picture has been loaded from or something else? Please be more clear. And if you try something already and "it does not work", then the exact error message you get is essential for us to help you. Regards, mav -- Black holes are the places where god divided by 0...

          C 1 Reply Last reply
          0
          • M mav northwind

            Still not sure what you really want. Are you trying to delete the file the picture has been loaded from or something else? Please be more clear. And if you try something already and "it does not work", then the exact error message you get is essential for us to help you. Regards, mav -- Black holes are the places where god divided by 0...

            C Offline
            C Offline
            CrazyDragon6384
            wrote on last edited by
            #5

            yes, i'm trying to delete the picture file has been loaded into PictureBox.:) I think the picture that has been loaded into PictureBox is saved into a "temp" memory or something else,isn't it?:((

            M 1 Reply Last reply
            0
            • C CrazyDragon6384

              yes, i'm trying to delete the picture file has been loaded into PictureBox.:) I think the picture that has been loaded into PictureBox is saved into a "temp" memory or something else,isn't it?:((

              M Offline
              M Offline
              mav northwind
              wrote on last edited by
              #6

              Ok, now that we know what your problem is, we can help you... :) You have to make sure the image file isn't being used any more. The most probable cause is that the image that has been assigned to the PictureBox hasn't been disposed of yet. First, you'll have to make sure you don't let any old references hanging around when you load an image into your PictureBox. For example, when setting an image to display you could write

              if (pictureBox1.Image != null)
              {
              pictureBox1.Image.Dispose();
              pictureBox1.Image = null;
              }
              pictureBox1.Image = newImageToShow;

              That way, only the image currently shown in the PictureBox is used. Before you can delete the file, you'll also have to remove any references, for example:

              private void buttonDelete_Pressed(object sender, EventArgs e)
              {
              pictureBox1.Image.Dispose();
              pictureBox1.Image = null;
              File.Delete(pathToCurrentImage);
              }

              Regards, mav -- Black holes are the places where god divided by 0...

              C 1 Reply Last reply
              0
              • M mav northwind

                Ok, now that we know what your problem is, we can help you... :) You have to make sure the image file isn't being used any more. The most probable cause is that the image that has been assigned to the PictureBox hasn't been disposed of yet. First, you'll have to make sure you don't let any old references hanging around when you load an image into your PictureBox. For example, when setting an image to display you could write

                if (pictureBox1.Image != null)
                {
                pictureBox1.Image.Dispose();
                pictureBox1.Image = null;
                }
                pictureBox1.Image = newImageToShow;

                That way, only the image currently shown in the PictureBox is used. Before you can delete the file, you'll also have to remove any references, for example:

                private void buttonDelete_Pressed(object sender, EventArgs e)
                {
                pictureBox1.Image.Dispose();
                pictureBox1.Image = null;
                File.Delete(pathToCurrentImage);
                }

                Regards, mav -- Black holes are the places where god divided by 0...

                C Offline
                C Offline
                CrazyDragon6384
                wrote on last edited by
                #7

                oh, pictureBox1.Image.Dispose(); :) thanks ! Then,can i ask you about form size? I have an user control added into a form. I used the following code in both Form_load() and Form_SizeChanged but the usc size wasn't changed: uscImage_NEW.UserControl1 usc=new uscImage_NEW.UserControl1(); private void Form1_SizeChanged(object sender, System.EventArgs e) { usc.Left=0; usc.Top=0; usc.Width=this.Width; usc.Height=this.Height; } how to solve this problem?

                M 1 Reply Last reply
                0
                • C CrazyDragon6384

                  oh, pictureBox1.Image.Dispose(); :) thanks ! Then,can i ask you about form size? I have an user control added into a form. I used the following code in both Form_load() and Form_SizeChanged but the usc size wasn't changed: uscImage_NEW.UserControl1 usc=new uscImage_NEW.UserControl1(); private void Form1_SizeChanged(object sender, System.EventArgs e) { usc.Left=0; usc.Top=0; usc.Width=this.Width; usc.Height=this.Height; } how to solve this problem?

                  M Offline
                  M Offline
                  mav northwind
                  wrote on last edited by
                  #8

                  Why don't you just anchor or dock the UC? Regards, mav -- Black holes are the places where god divided by 0...

                  C 1 Reply Last reply
                  0
                  • M mav northwind

                    Why don't you just anchor or dock the UC? Regards, mav -- Black holes are the places where god divided by 0...

                    C Offline
                    C Offline
                    CrazyDragon6384
                    wrote on last edited by
                    #9

                    I did with another objects such as one button, one lable or anything else in another project... its size was changed. In usc project, i tried but the usc size was unchanged.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups