10-15-2012 07:47 PM - edited 10-15-2012 07:51 PM
Hi All,
I'm trying to implement a bit of "MS paint" magic for a customer's dialog. I want to be able to drag and drop into a 2d picture control. Ideally, I'd like to be able to move this around and resize it once it's there, but let's start with the first part - how to drag and drop from e.g. the desktop onto the 2d picture control. The rest is nice-to-have but unnecessary.
I've seen a clever example on here using a transparent path control, but that's not going to cut it here (I have other events linked with that picture box, e.g. right now I have a double-click event adding text to the image).
Thanks for any ideas... I've looked briefly into using the windows API (i.e. constructor nodes) but, there be dragons.
Solved! Go to Solution.
10-15-2012 09:33 PM
@pobrepablo1 wrote:
Thanks for any ideas... I've looked briefly into using the windows API (i.e. constructor nodes) but, there be dragons.
You may want to use a .net picture box (if your program will always run on windows). You can register for callback events for drag and drop, then handle them in your event structure. I've been playing aroudn with .net controls lately, so I'll see if I can get this to work then attach my example.
10-15-2012 10:26 PM
@pobrepablo1 wrote:
Hi All,
I'm trying to implement a bit of "MS paint" magic for a customer's dialog. I want to be able to drag and drop into a 2d picture control. Ideally, I'd like to be able to move this around and resize it once it's there, but let's start with the first part - how to drag and drop from e.g. the desktop onto the 2d picture control. The rest is nice-to-have but unnecessary.
I've seen a clever example on here using a transparent path control, but that's not going to cut it here (I have other events linked with that picture box, e.g. right now I have a double-click event adding text to the image).
Thanks for any ideas... I've looked briefly into using the windows API (i.e. constructor nodes) but, there be dragons.
Well, it is possible and I got it working . Let me clean it up, close my references, etc and I will post it. You will have to use the .net control though so hopefully that is ok. You could manage it for the labVIEW picture control with a mix of .net or winAPI to handle the drag and drop and see if it's over your picture control and then somehow get the path of the drag and load the path into the LabVIEW picture control. But, you may just want to stick with it all using the .net control
10-15-2012 10:43 PM - edited 10-15-2012 10:45 PM
As promised, this should do it. You may need to adjust and put some checks in there to make sure the user doesn't drag more than one file, because it doesn't really make sense if they drag multiple files. You may also want to check the file types to make sure they are pictures etc but I will leave that up to you.
10-16-2012 11:19 AM
Thanks for the help, Greg. Would you mind exporting that to LV2011?
I'm not sure I can use the PictureBox method... I have some double-click events already associated with my 2d picture. I'll see if it's worth the effort converting.
10-16-2012 11:51 AM
It's not terribly difficult to get those events working with the picturebox. You just register for the events like I did with the dragdrop event, then handle it in your event structure appropriately.
10-16-2012 11:55 AM - edited 10-16-2012 11:59 AM
I'm thinking I can build on your code. Once a user has dragged into the window (anywhere is fine), I can perhaps copy it temporarily to PictureBox then move that pic to my 2d picture box. Regardless, thanks for your help, stellar coding!
10-16-2012 12:15 PM
Yup, there are lots of ways to make it work. You could possibly determine if a drag/drop was started just using the windows API and if it is, handle the mouse up event within LabVIEW. In the mouse up event handler, check if the mouse up coordinates are within the bounds of your picture control. If they are then load the image into your existing LabVIEW picture control. I think you could make this work, avoiding the .net picturebox all together. And thanks for the compliment 🙂