Чтобы ваш элемент управления TreeView мог перетаскивать в область рисования AutoCAD, вам нужно разместить / встроить свой элемент управления в PaletteSet в AutoCAD: Вот мой пример (я использую ListBox здесь, т.е.
public dragdropentity TestLB; //dragdropentity is my actuall control containing my ListBox
[CommandMethod("ListBox")]
public void lb()
{
if (this.TestLB == null)
{
myPaletteSet = new PaletteSet("Test ListBox", new Guid("{B32639EE-05DF-4C48-ABC4-553769C67995}"));
TestLB = new dragdropentity();
myPaletteSet.Add("LB", TestLB);
}
myPaletteSet.Visible = true;
}
Как только вы сможете отобразить TreeView в PaletteSet, вы можете вызвать метод DragDrop приложения AutoCAD. Вот сегмент кода из класса dragdropentity:
public partial class dragdropentity : UserControl
{
public dragdropentity()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// MessageBox.Show(listBox1.SelectedIndex.ToString() + '\n' + listBox1.SelectedItem.ToString());
pictureBox1.Load(@"D:\My\Documents\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary1\Images\" + listBox1.SelectedItem.ToString() + ".png");
}
void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int indexOfItem = listBox1.IndexFromPoint(e.X, e.Y);
if (indexOfItem >= 0 && indexOfItem < listBox1.Items.Count) // check that an string is selected
{
listBox1.DoDragDrop(listBox1.Items[indexOfItem], DragDropEffects.Copy);
}
// throw new System.NotImplementedException();
}
void listBox1_QueryContinueDrag(object sender, System.Windows.Forms.QueryContinueDragEventArgs e)
{
ListBox lb = (ListBox)sender;
textBox1.AppendText('\n' + e.Action.ToString() + '\n'+ this.Name.ToString());
if (e.Action == DragAction.Drop)
{
Autodesk.AutoCAD.ApplicationServices.Application.DoDragDrop(this, "Drag & drop successful!!!", System.Windows.Forms.DragDropEffects.All, new DragDrop());
}
}
}
DragDrop () - ваш собственный класс, обрабатывающий событие Drop. Вот мой код:
class DragDrop : DropTarget
{
public override void OnDrop(System.Windows.Forms.DragEventArgs e)
{
using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
// MyCommands mc = new MyCommands();
// mc.CircleJig();
//Call your own methods etc here.
}
}