изменения в формах

This commit is contained in:
just1valery 2022-10-23 09:56:51 +04:00
parent 1e2b24b8c8
commit 5ae6385332
4 changed files with 158 additions and 24 deletions

View File

@ -109,24 +109,25 @@ namespace WarmlyShip
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddShip_Click(object sender, EventArgs e)
{
FormShipConfig formShip = new();
formShip.AddEvent(new(AddShip));
formShip.Show();
}
private void AddShip(DrawningShip ship)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
MessageBox.Show("Перед добавлением объекта необходимо создать карту");
}
FormShip form = new();
if (form.ShowDialog() == DialogResult.OK)
else if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectShip(ship) != -1)
{
DrawningObjectShip ship = new(form.SelectedShip);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + ship != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>

View File

@ -36,7 +36,7 @@
this.panelYellow = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelGrey = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
@ -106,7 +106,7 @@
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelGrey);
this.groupBoxColors.Controls.Add(this.panelGray);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelRed);
@ -153,14 +153,14 @@
this.panelBlue.TabIndex = 1;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGrey
// panelGray
//
this.panelGrey.BackColor = System.Drawing.Color.Gray;
this.panelGrey.Location = new System.Drawing.Point(89, 96);
this.panelGrey.Name = "panelGrey";
this.panelGrey.Size = new System.Drawing.Size(50, 50);
this.panelGrey.TabIndex = 3;
this.panelGrey.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(89, 96);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(50, 50);
this.panelGray.TabIndex = 3;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
//
// panelGreen
//
@ -274,6 +274,8 @@
this.labelDopColor.TabIndex = 9;
this.labelDopColor.Text = "Доп. цвет";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter);
//
// labelBaseColor
//
@ -285,6 +287,8 @@
this.labelBaseColor.TabIndex = 8;
this.labelBaseColor.Text = "Цвет";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
//
// pictureBoxObject
//
@ -302,6 +306,7 @@
this.buttonOk.TabIndex = 10;
this.buttonOk.Text = "Добавить";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// buttonCancel
//
@ -348,7 +353,7 @@
private Panel panelYellow;
private Panel panelBlack;
private Panel panelBlue;
private Panel panelGrey;
private Panel panelGray;
private Panel panelGreen;
private Panel panelWhite;
private Panel panelRed;

View File

@ -12,11 +12,22 @@ namespace WarmlyShip
{
public partial class FormShipConfig : Form
{
private event ShipDelegate EventAddShip;
DrawningShip _ship = null;
public FormShipConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
DrawningShip _ship = null;
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
@ -30,6 +41,17 @@ namespace WarmlyShip
_ship?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(ShipDelegate ev)
{
if (EventAddShip == null)
{
EventAddShip = new ShipDelegate(ev);
}
else
{
EventAddShip += ev;
}
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
@ -60,5 +82,97 @@ namespace WarmlyShip
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddShip?.Invoke(_ship);
Close();
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "panelRed":
labelBaseColor.BackColor = Color.Red;
break;
case "panelBlack":
labelBaseColor.BackColor = Color.Black;
break;
case "panelGreen":
labelBaseColor.BackColor = Color.Green;
break;
case "panelYellow":
labelBaseColor.BackColor = Color.Yellow;
break;
case "panelBlue":
labelBaseColor.BackColor = Color.Blue;
break;
case "panelPurple":
labelBaseColor.BackColor = Color.Purple;
break;
case "panelGray":
labelBaseColor.BackColor = Color.DarkGray;
break;
case "panelWhite":
labelBaseColor.BackColor = Color.White;
break;
}
}
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "panelRed":
labelBaseColor.BackColor = Color.Red;
break;
case "panelBlack":
labelBaseColor.BackColor = Color.Black;
break;
case "panelGreen":
labelBaseColor.BackColor = Color.Green;
break;
case "panelYellow":
labelBaseColor.BackColor = Color.Yellow;
break;
case "panelBlue":
labelBaseColor.BackColor = Color.Blue;
break;
case "panelPurple":
labelBaseColor.BackColor = Color.Purple;
break;
case "panelGray":
labelBaseColor.BackColor = Color.DarkGray;
break;
case "panelWhite":
labelBaseColor.BackColor = Color.White;
break;
}
}
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip
{
/// <summary>
/// Делегат для передачи объекта-коробля
/// </summary>
/// <param name="car"></param>
public delegate void ShipDelegate(DrawningShip car);
}