using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Cruiser.Drawing; namespace Cruiser { public partial class FormCruiserConfig : Form { /// /// Переменная-выбранная лайнера /// DrawingCruiser? _cruiser = null; /// /// Событие /// private event Action? EventAddCruiser; /// /// Конструктор /// public FormCruiserConfig() { InitializeComponent(); panelColorRed.MouseDown += panelColor_MouseDown; panelColorSienna.MouseDown += panelColor_MouseDown; panelColorForestGreen.MouseDown += panelColor_MouseDown; panelColorAquamarine.MouseDown += panelColor_MouseDown; panelColorCrimson.MouseDown += panelColor_MouseDown; panelColorDodgerBlue.MouseDown += panelColor_MouseDown; panelColorGold.MouseDown += panelColor_MouseDown; panelColorPlum.MouseDown += panelColor_MouseDown; buttonCancel.Click += (s, e) => Close(); } /// /// Отрисовать лайнер /// private void DrawCruiser() { Bitmap bmp = new(pictureBoxToCruiser.Width, pictureBoxToCruiser.Height); Graphics gr = Graphics.FromImage(bmp); _cruiser?.SetPosition(15, 15); _cruiser?.DrawTransport(gr); pictureBoxToCruiser.Image = bmp; } /// Добавление события /// /// Привязанный метод public void AddEvent(Action ev) { if (EventAddCruiser == null) { EventAddCruiser = ev; } else { EventAddCruiser += ev; } } /// /// Добавление лайнера /// /// /// private void buttonAdd_Click(object sender, EventArgs e) { EventAddCruiser?.Invoke(_cruiser); Close(); } /// /// Передаем информацию при нажатии на Label /// /// /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } /// /// Проверка получаемой информации (ее типа на соответствие требуемому) /// /// /// private void PanelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } /// /// Действия при приеме перетаскиваемой информации /// /// /// private void PanelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data?.GetData(DataFormats.Text).ToString()) { case "labelCruiser": //переделал из за изменения конструкторов (см. комментарии там) _cruiser = new DrawingCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.Orchid, pictureBoxToCruiser.Width, pictureBoxToCruiser.Height); break; case "labelProCruiser": //переделал из за изменения конструкторов (см. комментарии там) _cruiser = new DrawingProCruiser((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.Orchid, Color.Aquamarine, checkBoxRockMines.Checked, checkBoxHelipad.Checked, pictureBoxToCruiser.Width, pictureBoxToCruiser.Height); break; } DrawCruiser(); } private void panelColor_MouseDown(object sender, MouseEventArgs e) { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); } private void labelColor_DragEnter(object sender, DragEventArgs e) { if (e.Data?.GetDataPresent(typeof(Color)) ?? false) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } private void labelColor_DragDrop(object sender, DragEventArgs e) { if (_cruiser == null) return; switch (((Label)sender).Name) { case "labelColor": _cruiser.setBodyColor((Color)e.Data.GetData(typeof(Color))); break; case "labelDopColor": if (!(_cruiser is DrawingProCruiser)) return; (_cruiser as DrawingProCruiser).setElementColor((Color)e.Data.GetData(typeof(Color))); break; } DrawCruiser(); } } }