LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Drag and drop image into 2d Picture

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 8
(4,613 Views)

@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.

0 Kudos
Message 2 of 8
(4,596 Views)

@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 Smiley Happy. 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

0 Kudos
Message 3 of 8
(4,591 Views)

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.

 

 

Download All
Message 4 of 8
(4,589 Views)

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. 

 

0 Kudos
Message 5 of 8
(4,561 Views)
Solution
Accepted by topic author pobrepablo1

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.

 

 

Message 6 of 8
(4,557 Views)

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!

Message 7 of 8
(4,556 Views)

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 🙂

0 Kudos
Message 8 of 8
(4,551 Views)