private void DxContainer_DragDrop(object sender, DragEventArgs e) { lock (this) { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { return; } if (!AssertLayerSelected()) { return; } string[] data = (string[])e.Data.GetData(DataFormats.FileDrop); System.Drawing.Point p = PointToClient(new System.Drawing.Point(e.X, e.Y)); foreach (string file in data) { System.Drawing.Bitmap bmp; try { bmp = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(file); } catch { continue; } if (ImageDropped != null) { ImageDropped.Invoke(selectedBoard, bmp, Path.GetFileNameWithoutExtension(file), new Point(PhysicalToVirtual(p.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0), PhysicalToVirtual(p.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0))); } } } }
/// <summary> /// Drag drop /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DxContainer_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { lock (this) { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { return; } if (!AssertLayerSelected()) return; string[] data = (string[])e.Data.GetData(DataFormats.FileDrop); // be warned when run under visual studio. it inherits VS's scaling and VS's window location System.Windows.Point p = PointToScreen(new System.Windows.Point(e.X, e.Y)); foreach (string file in data) { System.Drawing.Bitmap bmp; try { bmp = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(file); } catch { continue; } if (ImageDropped != null) ImageDropped.Invoke(selectedBoard, bmp, Path.GetFileNameWithoutExtension(file), new Point(PhysicalToVirtual((int) p.X, selectedBoard.CenterPoint.X, selectedBoard.hScroll, 0), PhysicalToVirtual((int) p.Y, selectedBoard.CenterPoint.Y, selectedBoard.vScroll, 0))); } } }