Product : Engine, Version : 5.0.1.1036, ArticleID : 41023948

HowTo : How to add Drag-Drop functionality in c# application

Article41023948
TypeHowTo
ProductEngine
Version5.0.1.1036
Date Added4/20/2005
Submitted byHans Leirvik
Keywords

Subject

How to add Drag-Drop functionality in c# application

Summary

How to add Drag-Drop functionality in c# application

Solution

Add two buttons in your application (one for opening a file, and one for selecting objects).

Add two VectorDraw windows (one called "source" and one called "dest")

Add the following code:

 

private void OpenFile_Click(object sender, System.EventArgs e)

{

     bool a=source.ActiveDocument.Open("",0,0);

     if (a==true){button1.Enabled=true;}

}

 

private void Form1_Load(object sender, System.EventArgs e)

{

     VDProLib5.vdSelection selset;

     selset=source.ActiveDocument.Selections.Add("DragObjects");

     button1.Enabled=false;

}

 

private void vdpro1_MouseDownEvent(object sender, AxVDProLib5._DVdrawEvents_MouseDownEvent e)

{

     if (source.CommandAction.OpenLoops == 0)

     {

          source.CommandAction.DoDragDrop ("PREV", VDProLib5.VdDropEffect.VdDropEffect_Copy,new object[] {0,0,0} , 100, 100, 3);

     }

}

 

private void source_VDDragDropEx(object sender, AxVDProLib5._DVdrawEvents_VDDragDropExEvent e)

{

     e.cancel = 1; //Don't do Drop here

}

 

private void source_VDDragEnterEx(object sender, AxVDProLib5._DVdrawEvents_VDDragEnterExEvent e)

{

     e.dropEffect = VDProLib5.VdDropEffect.VdDropEffect_None; //Nothing to appear here

     e.cancel = 1;

}

 

private void dest_VDDragDropEx(object sender, AxVDProLib5._DVdrawEvents_VDDragDropExEvent e)

{

     int index;

     object handle;

     VDProLib5.vdBlock block;

     VDProLib5.vdInsert ins;

     index = e.dataObject.FindItemType(e.dataObject.VdrawClipboardFormat);

     if (index != 65535)

     {

          int kkk;

          kkk = e.dataObject.VdrawClipboardFormat;

          handle = e.dataObject.GetItem(index, ref kkk); //e.dataObject.VdrawClipboardFormat

          block = dest.ActiveDocument.Blocks.AddFromMemory("MyDragBlock", handle);

          if (block!=null)

          {

               ins = dest.ActiveDocument.Entities.InsertBlock(new object[] {e.xpos,e.ypos}, block.Name, 1, 1, 0);

               if (ins!=null) e.cancel=1;

               ins.Invalidate();

          }

     }

}

 

private void dest_VDDragEnterEx(object sender, AxVDProLib5._DVdrawEvents_VDDragEnterExEvent e)

{

     int index;

     index = e.dataObject.FindItemType(e.dataObject.VdrawClipboardFormat);

     if (index == 65535)

     {

          e.dropEffect=VDProLib5.VdDropEffect.VdDropEffect_None;

          e.cancel=1;

     }

     e.dropEffect=VDProLib5.VdDropEffect.VdDropEffect_Copy;

}

 

private void dest_VDDragOverEx(object sender, AxVDProLib5._DVdrawEvents_VDDragOverExEvent e)

{

     int index;

     index = e.dataObject.FindItemType(e.dataObject.VdrawClipboardFormat);

     if (index == 65535)

     {

          e.dropEffect=VDProLib5.VdDropEffect.VdDropEffect_None;

          e.cancel=1;

     }

     e.dropEffect=VDProLib5.VdDropEffect.VdDropEffect_Copy;

}

 

private void button1_Click(object sender, System.EventArgs e)

{

     source.CommandAction.CmdSelect("USER");

}