wpf - C# Drag & Drop Multiple Images within Canvas -


I have received the following code to drag and drop pictures inside my canvas:

 < Code> img.AllowDrop = true; Img.previewMouseLeftButtonDown + = this.MouseLeftButtonDown; Img.PreviewMouseMove + = this.MouseMove; Img.PreviewMouseLeftButtonUp + = this.PreviewMouseLeftButtonUp; Private object hill object; Private double first expo, first w po; Private zero mouse leftbootdown (object sender, mousebuttonEurrentErgus E) {// In this event, we get the current mouse position on the controls to use it in the mouse move event. Image img = sender as image; Canvas canvas = IMG Generator as canvas; FirstXPos = E. Gateptation (IMG). X; First Y POS = E. Gateptation (IMG). why; MovingObject = Sender; // Currently keep the image being dragged to the top of others int top = Canvas.GetZIndex (img); Exotic hair (baby kid in canvas) if (top  canvas.getsindex (child)) top = canvas.gategidx (hair); Canvas SetZIndex (IMG, Top + 1); } Private Whoid Maumvov (object sender, mouse events Aarjis e) (if (e. Leftbutn == mouse Btntn Press & amp; from == moving object) {Image img = sender as the image; canvas = IMG. Canvas as a parent, double new left = e. Getpojishn (canvas). X - the first X-piece - canvas. margins. left; // new left-right border within the canvas? If (newLeft & gt; canvas.Margin.Left + Canvas.ActualWidth - img.ctualWidth) newLeft = canvas.Margin.Left + canvas.va Tvik wide - IMG. Wastvikwarth; // canvas within New Left left? Else if (newLeft & lt; canvas.Margin.Left) newLeft = canvas.Margin.Left; Img.SetValue (canvas. Leftproprti, new elevators); Double Nutop = e. Getpojhishn (canvas). Wi - first YPos - canvas. margin. tap; // Nitop within the lower limits of the canvas? If (Nyatop & gt; canvas. margin. hat + canvas. Wastvikhait - IMG. Wastvikhait ) NewTop = canvas margin top + canvas realheat - IMG. New Top within the top of the actualhigh; // canvas? And if (newtop & lt; Canvas Margin. Tap) newTop = canvas.Margin.Top; Img.SetValue (Canvas TopProperty, newTop); }}  

This code allows me to drag and drop images without the canvas.

Now I just need to be able to do two more things:

  1. Fix a small bug where my mouse image slips, when I get them let me draw faster so I am often, even when I'm dragging the image only carry around that fast ..
  2. many images by enabling you to drag and drop, the first By choosing multiple times, and then

PS: My first question can be found.

You want the cursor to turn the mouse over the image to prevent the mouse from closing the mouse. Are there. Capture (Image Reference), with the mouse you can leave it on the mouse. Capture (free) - Andy February 18 15:58

After using the tips of Andy, adding:

  Mouse.Capture (img); MouseLeftButtonDown -  

, and

  icons at the bottom of the function. Capture (empty); PreviewMouseLeftButtonUp-function below  

, it works like a charm Thanks a lot Andy!


Comments