иправила ошибки,но не все

This commit is contained in:
ALINA_KURBANOVA 2023-11-14 22:19:16 +04:00
parent 39c5d85bda
commit e0d54b8bcc
5 changed files with 120 additions and 44 deletions

View File

@ -33,5 +33,9 @@
Weight = weight;
BodyColor = bodyColor;
}
public void ChangeBodyColor(Color color)
{
BodyColor = color;
}
}
}

View File

@ -22,6 +22,10 @@
Trumpet = trumpet;
Luggage = luggage;
}
public void ChangeAdditionalColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@ -9,6 +9,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.DataFormats;
using WarmlyLocomotive.DrawningObjects;
namespace WarmlyLocomotive
{
public partial class FormWarmlyLocomotiveCollection : Form
@ -73,6 +76,7 @@ namespace WarmlyLocomotive
ReloadObjects();
}
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
@ -80,9 +84,6 @@ namespace WarmlyLocomotive
/// <param name="e"></param>
private void buttonAdd_Click(object sender, EventArgs e)
{
var formWarmlyLocomotiveConfig = new FormWarmlyLocomotiveConfig();
formWarmlyLocomotiveConfig.AddEvent(Addwarmlylocomotive);
formWarmlyLocomotiveConfig.Show();
if (listBoxStorages.SelectedIndex == -1)
{
return;
@ -93,10 +94,11 @@ namespace WarmlyLocomotive
{
return;
}
WarmlyLocomotiveForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedWarmlyLocomotive)
FormWarmlyLocomotiveConfig form = new FormWarmlyLocomotiveConfig(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
form.Show();
Action<DrawningWarmlyLocomotive>? warmlydelegate = new((m) => {
bool q = (obj + m);
if (q)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
@ -105,8 +107,10 @@ namespace WarmlyLocomotive
{
MessageBox.Show("Не удалось добавить объект");
}
}
});
form.AddEvent(warmlydelegate);
}
/// <summary>
/// Удаление объекта из набора
/// </summary>

View File

@ -50,8 +50,8 @@
PanelColor = new Panel();
buttonCancel = new Button();
buttonOk = new Button();
label6 = new Label();
label5 = new Label();
labelAdditionalColor = new Label();
labelMainColor = new Label();
groupBoxOptions.SuspendLayout();
groupBoxColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
@ -98,6 +98,7 @@
labelModifiedObject.TabIndex = 3;
labelModifiedObject.Text = "Продвинутый";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// groupBoxColor
//
@ -259,8 +260,8 @@
PanelColor.AllowDrop = true;
PanelColor.Controls.Add(buttonCancel);
PanelColor.Controls.Add(buttonOk);
PanelColor.Controls.Add(label6);
PanelColor.Controls.Add(label5);
PanelColor.Controls.Add(labelAdditionalColor);
PanelColor.Controls.Add(labelMainColor);
PanelColor.Controls.Add(pictureBoxObject);
PanelColor.Location = new Point(512, 30);
PanelColor.Name = "PanelColor";
@ -289,25 +290,29 @@
buttonOk.UseVisualStyleBackColor = true;
buttonOk.Click += buttonOk_Click_1;
//
// label6
// labelAdditionalColor
//
label6.BorderStyle = BorderStyle.FixedSingle;
label6.Location = new Point(129, 13);
label6.Name = "label6";
label6.Size = new Size(80, 30);
label6.TabIndex = 3;
label6.Text = "Доп. цвет";
label6.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
labelAdditionalColor.Location = new Point(129, 13);
labelAdditionalColor.Name = "labelAdditionalColor";
labelAdditionalColor.Size = new Size(80, 30);
labelAdditionalColor.TabIndex = 3;
labelAdditionalColor.Text = "Доп. цвет";
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop;
labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter;
//
// label5
// labelMainColor
//
label5.BorderStyle = BorderStyle.FixedSingle;
label5.Location = new Point(26, 13);
label5.Name = "label5";
label5.Size = new Size(80, 30);
label5.TabIndex = 2;
label5.Text = "Цвет";
label5.TextAlign = ContentAlignment.MiddleCenter;
labelMainColor.BorderStyle = BorderStyle.FixedSingle;
labelMainColor.Location = new Point(26, 13);
labelMainColor.Name = "labelMainColor";
labelMainColor.Size = new Size(80, 30);
labelMainColor.TabIndex = 2;
labelMainColor.Text = "Цвет";
labelMainColor.TextAlign = ContentAlignment.MiddleCenter;
labelMainColor.DragDrop += labelMainColor_DragDrop;
labelMainColor.DragEnter += labelMainColor_DragEnter;
//
// FormWarmlyLocomotiveConfig
//
@ -349,8 +354,8 @@
private Label labelModifiedObject;
private PictureBox pictureBoxObject;
private Label labelSimpleObject;
private Label label6;
private Label label5;
private Label labelAdditionalColor;
private Label labelMainColor;
private Button buttonCancel;
private Button buttonOk;
public Panel PanelColor;

View File

@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Tracing;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using WarmlyLocomotive.DrawningObjects;
using WarmlyLocomotive.Entities;
using static WarmlyLocomotive.FormWarmlyLocomotiveConfig;
namespace WarmlyLocomotive
{
@ -15,21 +9,22 @@ namespace WarmlyLocomotive
/// Делегат для передачи объекта-тепловоза
/// </summary>
/// <param name="warmlylocomotive"></param>
public delegate void CarDelegate(DrawningWarmlyLocomotive warmlylocomotive);
public partial class FormWarmlyLocomotiveConfig : Form
{
public int _pictureWidth { get; private set; }
public int _pictureHeight { get; private set; }
/// <summary>
/// Переменная-выбранная машина
/// Переменная
/// </summary>
DrawningWarmlyLocomotive? _warmlylocomotive = null;
/// <summary>
/// Событие
/// </summary>
private event CarDelegate? EventAddWarmlyLocomotive;
public event Action<DrawningWarmlyLocomotive>? EventAddWarmlyLocomotive;
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
public void AddEvent(CarDelegate ev)
public void AddEvent(Action<DrawningWarmlyLocomotive> ev)
{
if (EventAddWarmlyLocomotive == null)
{
@ -41,6 +36,16 @@ namespace WarmlyLocomotive
}
}
/// <summary>
/// Передача цвета при нажатии на одну из Panel с цветом
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Конструктор
/// </summary>
public FormWarmlyLocomotiveConfig()
@ -118,8 +123,62 @@ namespace WarmlyLocomotive
}
DrawCar();
}
// TODO Реализовать логику смены цветов: основного и дополнительного(для продвинутого объекта)
/// <summary>
/// Проверка для базового цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelMainColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)) && _warmlylocomotive != null)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемого цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelMainColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
_warmlylocomotive.EntityWarmlyLocomotive.ChangeBodyColor(color);
DrawCar();
}
/// <summary>
/// Проверка для дополнительного цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)) && _warmlylocomotive != null && _warmlylocomotive is DrawningWarmlyLocomotiveWithTrumpet)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Получение дополнительного цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
EntityWarmlyLocomotiveWithTrumpet? _warmlylocomotivePro = _warmlylocomotive.EntityWarmlyLocomotive as EntityWarmlyLocomotiveWithTrumpet;
_warmlylocomotivePro.ChangeAdditionalColor(color);
DrawCar();
}
/// Добавление машины
/// </summary>
/// <param name="sender"></param>