Remove image that was dragged and dropped.

I have a drag and drop program.

i need to remove the image that was being dropped into the picturebox.

any idea how it goes?
string[] Images = new string[] { ImagePath + "bbb.jpg" };






            foreach (string img in Images)
            {
                PictureBox PB = new PictureBox();
                PB.Width = PB.Height = 43;
                PB.Location = new Point(38, 13);
                PB.Image = Image.FromFile(img);
                PB.MouseDown += new MouseEventHandler(PB_MouseDown);
                PB.MouseHover += new System.EventHandler(PB_MouseHover);
                PB.MouseLeave += new System.EventHandler(PB_MouseLeave);
                this.Controls.Add(PB);



            }
        }




        void PB_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                x = e.X;
                y = e.Y;


                PictureBox pictureBox = new PictureBox();
                pictureBox.Image = ((PictureBox)sender).Image;
                pictureBox.Top = ((PictureBox)sender).Top;
                pictureBox.Width = ((PictureBox)sender).Width;
                pictureBox.Height = ((PictureBox)sender).Height;
                pictureBox.Left = ((PictureBox)sender).Left;
                pictureBox.MouseMove += new MouseEventHandler(PictureBox_MouseMove);
                pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
                this.Controls.Add(pictureBox);
                pictureBox.BringToFront();

                MouseUPDOWN();

             

            }





  void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                x = e.X;
                y = e.Y;
            }
        }

       

        void PictureBox_MouseMove(object sender, MouseEventArgs e)
        {
           
           if (e.Button == MouseButtons.Left)
           {

                ((PictureBox)sender).Left += (e.X - x);
                ((PictureBox)sender).Top += (e.Y - y);
                ((PictureBox)sender).BringToFront();
           }
        }

        


   

        #region MouseAPIs
        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;

        public void MouseUPDOWN()
        {
            mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
        }
        #endregion

       
        }

Open in new window

securedungeonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
You have to use DragEnter,DragOver,DragDrop and DragLeave events. Before that you will have to set some properties on the picturebox like AllowDrop.

Check these articles for better understanding.

http://www.codeproject.com/KB/cs/dandtutorial.aspx
http://www.dotnetcurry.com/ShowArticle.aspx?ID=179&AspxAutoDetectCookieSupport=1
0
securedungeonAuthor Commented:
my drag and drop is working perfectly fine.

i wan to have a function that can remove the image that was dragged and dropped into the picturebox.
0
SriVaddadiCommented:
set the image property to null and call refresh method.

Picturebox.Image = null;
Picturebox.Refresh();

This should do the trick
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

securedungeonAuthor Commented:
the code mentioned above works but how does it imply into the drag and drop codes that i had pasted above?
0
SriVaddadiCommented:
"i need to remove the image that was being dropped into the picturebox. " I thought you want to remove the image from the picture box.

When do you want to remove the image. Also Could you provide more information about your task at hand?

0
securedungeonAuthor Commented:
When the picturebox was dragged into the PANEL which is a picturebox, the user decide to remove one of the picturebox that was removed when the user click on a button.
0
SriVaddadiCommented:
If i understand correctly,

You have a picturebox onto which users can drag other picture box control or an image. Once dragged onto it the picture is set.

Now to remove the dragged picture box, user has to click on a button and select the picture box to be removed?

Sounds right?
0
securedungeonAuthor Commented:
Yes, mr. thank u so much.
0
SriVaddadiCommented:
Now on clicking the button, set target picturebox (panel) image to null

Picturebox.Image = null;
Picturebox.Refresh();
0
securedungeonAuthor Commented:
i am suppose to be remove the image that was dragged onto the panel (picturebox) and the solution given is not working.

thank u so much as well.
0
securedungeonAuthor Commented:
is there any event handler codes that i need to add on to activate it?

could you refer to my code attached above?
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
It's hard to "visualize" this kind of problem just looking at the code.  Can you attach or upload a small sample project somewhere so we can see it better?
0
securedungeonAuthor Commented:
the codes are attached are exactly the same as my project.

if u don mind, i would like to email u the project but it failed on me cus hotmail said yr email is incorrect.

thank u.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You can upload it here:
http://www.ee-stuff.com/
0
securedungeonAuthor Commented:
To download the file, you must be logged into EE-Stuff. Here are two pages that will display your file, if logged in:

View all files for Question ID: 26006866
https://filedb.experts-exchange.com/incoming/ee-stuff/7901-DD4.rarhttps://filedb.experts-exchange.com/incoming/ee-stuff/7903-DD4.zip


Direct link to your file
https://filedb.experts-exchange.com/incoming/ee-stuff/7901-DD4.rar


thank u.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
A .rar?  How about a .zip instead?
0
SriVaddadiCommented:
Pls find attached the code as a Zip (Rar file renamed to zip).

Double click the project file.
DD4.zip
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Ok...renaming a .rar to a .zip doesn't make it a zip....  =\
0
SriVaddadiCommented:
Sorry Mr.Idle_Mind, Code I attached was a solution and not what author has uploaded. More over, Zip/rar can be interchangeably used as both Winrar and Winzip support the other format.

Mr. securedungeon, Pls find the solution attached in my prev post. I guess its a bit confusion in the context as i have not mentioned that it was a solution.

Sorry for the confusion
0
securedungeonAuthor Commented:
Hi SriVaddadi,

The solution attached does not suit into my requirements at all.

The drag and drop image does not remove itself when i click on the button.

And the drag and drop images are not MULTIPLE anymore.

The foreach loop allows multiple images to be dragged and dropped into the PANEL.
not left ONE only.


Thank u for yr help .



AND, Mr.Idle_Mind,
What i had attached is zip file.
i attached the zip file again.
 View all files for Question ID: 26006866
https://filedb.experts-exchange.com/incoming/ee-stuff/7901-DD4.rarhttps://filedb.experts-exchange.com/incoming/ee-stuff/7903-DD4.zip


Direct link to your file
https://filedb.experts-exchange.com/incoming/ee-stuff/7903-DD4.zip 


Thank u for all the help!
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Just as SriVaddadi originally, proposed simply set the PictureBox.Image property to null in your PB_MouseDown() method:
        void PB_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                x = e.X;
                y = e.Y;


                PictureBox pictureBox = new PictureBox();
                pictureBox.Image = ((PictureBox)sender).Image;
                ((PictureBox)sender).Image = null; // <------------ set the original PB to blank ------- ****
                pictureBox.Top = ((PictureBox)sender).Top;
                pictureBox.Width = ((PictureBox)sender).Width;
                pictureBox.Height = ((PictureBox)sender).Height;
                pictureBox.Left = ((PictureBox)sender).Left;
                pictureBox.MouseMove += new MouseEventHandler(PictureBox_MouseMove);
                pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
                this.Controls.Add(pictureBox);
                pictureBox.BringToFront();

                MouseUPDOWN();

             

            }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
securedungeonAuthor Commented:
NO. it does not work.

Once the button is click, the image will be removed.

If the solution that was proposed earlier, i will not be posting anymore.

Thank u.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
?

It worked for me...and I am using the sample project provided by you.  When I clicked and dragged the image, the original picturebox become blank.

Please explain then in more detail what should happen.  Make a screencast and talk about it.  Take a bunch of screenshots and label them.

Something!...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.