public FormMain() { InitializeComponent(); ImageController.Init(); var parent = panelElements; var width = parent.Width; var height = 150; menuElements = (new IMenuElement[] { new MenuComputerElement("Компьютер", width, height, ImageController.Open("computer.svg") as Image, ButtonPK_MouseDown), new MenuRouterElement("Роутер", width, height, ImageController.Open("router.svg") as Image, ButtonPK_MouseDown), }).ToList(); DragAndDropController.FormMain = this; }
private void panelConnection_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetData(typeof(MenuComputerElement)) is MenuComputerElement) { var point = DragAndDropController.ConvertPoint(e.X, e.Y); panelConnection.Controls.Add(new Computer(50, 50, ImageController.Open("computer.svg") as Image, Element_MouseDown, point.X - 25, point.Y - 25, 1)); } else if (e.Data.GetData(typeof(MenuRouterElement)) is MenuRouterElement) { var point = DragAndDropController.ConvertPoint(e.X, e.Y); panelConnection.Controls.Add(new Router(50, 50, ImageController.Open("router.svg") as Image, Element_MouseDown, point.X - 25, point.Y - 25, 8)); } else if (e.Data.GetData(typeof(Computer)) is Computer) { var point = DragAndDropController.ConvertPoint(e.X - DragAndDropController.DraggedObject.Width / 2, e.Y - DragAndDropController.DraggedObject.Height / 2); DragAndDropController.DraggedObject.Location = point; } StopDragAndDrop(); }