Drag and Drop

It is possible to drag and drop an Image between multiple DicomViewer controls even between different version of DicomObjects.

Simple sample code below shows how it can be done.

Drag and Drop in .NET version of DicomObjects

private void Viewer1_MouseDown(object sender, MouseEventArgs e)
{
	if (e.Button == System.Windows.Forms.MouseButtons.Left)
	{
		DicomImage img = Viewer1.Images[0];             
		Viewer1.DoDragDrop(img, System.Windows.Forms.DragDropEffects.Copy);
	}
}

private void Viewer2_DragDrop(object sender, DragEventArgs e)
{
	System.Windows.Forms.IDataObject io = ((System.Windows.Forms.IDataObject)(e.Data));
	Viewer2.Images.Add(io.GetData(typeof(DicomImage)) as DicomImage);
}

private void Form1_Load(object sender, EventArgs e)
{
	Viewer1.Images.Read("DICOMImage_1");
}

private void Viewer2_DragEnter(object sender, DragEventArgs e)
{
	if (e.Data.GetFormats().Contains("DicomObjects.DicomImage"))
		e.Effect = DragDropEffects.Copy;
}


Drag and Drop from DicomViewer COM object, to another application in .NET environment.

In order to enable drag and drop from a DicomViewer COM object, in .NET environment, Follow the following steps:

  this.axDicomViewer1.MouseDownEvent += new AxDicomObjects.IDicomViewerEvents_MouseDownEventHandler(this.axDicomViewer1_MouseDown);

private void axDicomViewer1_MouseDown(object sender, IDicomViewerEvents_MouseDownEvent e)
{
   if (((e.button& 1) != 0)) //left button clicked
   {
      Array arr = (Array)image.WriteArray(true,null,"100");  //convert the image to an array
      byte [] ba = new byte[arr.LongLength];
      arr.CopyTo(ba,0);
      axDicomViewer1.DoDragDrop(ba, DragDropEffects.Copy);   //send the array as the drag/drop object
   }
}

this.TARGET_CONTROL.DragDrop += new System.Windows.Forms.DragEventHandler(drag drop);

private void drag drop(Object sender, DragEventArgs e)
{
   try
   {
       DicomImage di;
       IDataObject io = ((IDataObject)(e.Data));
       DicomImages images = new DicomImages();
       byte [] ba = (byte[]) io.GetData("System.Byte[]");
       di = (DicomImage) images.ReadArray(ba);
       if (di!=null)
       {
         //your DicomImage is now imported. you can now use it.
       }
   }
   catch
   {
      //Handle exceptions here, usually when you drag something irrelevant to this code to your control.
   }
}


We use cookies to give you the best possible experience on our website. By continuing to use this website, you agree with our use of cookies. for more information please click HERE