|
-
Aug 19th, 2012, 03:26 PM
#1
Thread Starter
Lively Member
How to drag and drop image from PictureBox to file.
Hi all.
Is it possible to drag and drop a drawn image from a PictureBox and save it to file.
EX: If I drag and drop the PictureBox to my desktop I need it to save it as a .bmp
Here's my save to file code.
Code:
mPrintBitMap = New Bitmap(Piclvl1.Width, Piclvl1.Height)
Dim lRect As System.Drawing.Rectangle
lRect.Width = Piclvl1.Width
lRect.Height = Piclvl1.Height
Me.DrawToBitmap(mPrintBitMap, lRect)
Brian Henry
Visual Studio 2001 to 2019
Java/Android
ISaGRAF
-
Aug 19th, 2012, 03:44 PM
#2
Re: How to drag and drop image from PictureBox to file.
Er ... not seeing any save to file code there.
In principle, yes it's possible but I'm not sure how it's preferable to the standard name it, save it routine.
-
Aug 19th, 2012, 09:09 PM
#3
Re: How to drag and drop image from PictureBox to file.
 Originally Posted by dunfiddlin
Er ... not seeing any save to file code there.
In principle, yes it's possible but I'm not sure how it's preferable to the standard name it, save it routine.
Drag and drop would be quicker for the lazy people using his application.
I would say you'd need to use the drag event handlers for that picturebox, then read the stream of the picturebox.image to the location where you've "dragged" the image to in the filesystem. Which probably would require some unmanaged API call, or Windows Messages. That's without much thought into this, but that's how you'd go about it.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
Aug 19th, 2012, 11:05 PM
#4
Re: How to drag and drop image from PictureBox to file.
You can only initiate the drag operation. It will be Windows Explorer that needs to handle the drop operation. As such, you need to provide data in a format that Windows Explorer will understand. The Control.DoDragDrop method says:
The allowedEffects parameter determines which drag operations can occur. If the drag operation needs to interoperate with applications in another process, data should either be a base managed class ( String, Bitmap, or Metafile), or an object that implements ISerializable or IDataObject.
As you're using a Bitmap, you should be good to go. There's a little more to it than this but, basically, you call DoDragDrop and pass your Bitmap to the 'data' parameter. There are lots of examples of drag & drop code around. I've added one in the CodeBank myself, although it just works within the same application. It will still show you how to call DoDragDrop and handle the appropriate events. There's a link to my CodeBank submissions in my signature.
That said, given that the user would still have to navigate to the desired folder in Windows Explorer and still have to name the file, just using a SaveFileDialog seems less trouble to me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|