PIbd-21. Danilov V.V. Lab work 05 #5
@ -60,5 +60,10 @@ namespace Project_DumpTruck.DrawningObjects
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
(EntityTruck as EntityDumpTruck).SetAdditionalColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ namespace Project_DumpTruck.DrawningObjects
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
public int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
public int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
@ -224,5 +224,10 @@ namespace Project_DumpTruck.DrawningObjects
|
||||
g.DrawEllipse(penBlack, _startPosX + 22, _startPosY + 35, 20, 20);
|
||||
g.DrawEllipse(penBlack, _startPosX + 80, _startPosY + 35, 20, 20);
|
||||
}
|
||||
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
EntityTruck.SetBodyColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,5 +39,10 @@ namespace Project_DumpTruck.Entities
|
||||
BodyKit = bodyKit;
|
||||
Tent = tent;
|
||||
}
|
||||
|
||||
public void SetAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,5 +40,10 @@ namespace Project_DumpTruck.Entities
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public void SetBodyColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
@ -51,32 +52,39 @@ namespace Project_DumpTruck
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void buttonAddTruck_Click(object sender, EventArgs e)
|
||||
private void AddTruck(DrawningTruck truck)
|
||||
{
|
||||
truck._pictureWidth = pictureBoxCollection.Width;
|
||||
truck._pictureHeight = pictureBoxCollection.Height;
|
||||
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormDumpTruck form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
|
||||
if (obj + truck != -1)
|
||||
{
|
||||
if (obj + form.selectedTruck != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAddTruck_Click(object sender, EventArgs e)
|
||||
{
|
||||
var formTruckConfig = new FormTruckConfig();
|
||||
formTruckConfig.AddEvent(AddTruck);
|
||||
formTruckConfig.Show();
|
||||
}
|
||||
|
||||
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
||||
|
@ -29,8 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBox1 = new GroupBox();
|
||||
label4 = new Label();
|
||||
label3 = new Label();
|
||||
labelModifiedObject = new Label();
|
||||
labelSimpleObject = new Label();
|
||||
groupBox2 = new GroupBox();
|
||||
panelPurple = new Panel();
|
||||
panelBlack = new Panel();
|
||||
@ -46,24 +46,24 @@
|
||||
numericUpDownSpeed = new NumericUpDown();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
panelObject = new Panel();
|
||||
pictureBoxObject = new PictureBox();
|
||||
panel9 = new Panel();
|
||||
label6 = new Label();
|
||||
label5 = new Label();
|
||||
labelAdditionalColor = new Label();
|
||||
labelColor = new Label();
|
||||
buttonOk = new Button();
|
||||
button2 = new Button();
|
||||
buttonCancel = new Button();
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||
panelObject.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||
panel9.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(label4);
|
||||
groupBox1.Controls.Add(label3);
|
||||
groupBox1.Controls.Add(labelModifiedObject);
|
||||
groupBox1.Controls.Add(labelSimpleObject);
|
||||
groupBox1.Controls.Add(groupBox2);
|
||||
groupBox1.Controls.Add(checkBoxTent);
|
||||
groupBox1.Controls.Add(checkBoxBodyKit);
|
||||
@ -78,26 +78,27 @@
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Параметры";
|
||||
//
|
||||
// label4
|
||||
// labelModifiedObject
|
||||
//
|
||||
label4.BorderStyle = BorderStyle.FixedSingle;
|
||||
label4.Location = new Point(344, 156);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(94, 23);
|
||||
label4.TabIndex = 8;
|
||||
label4.Text = "Продвинутый";
|
||||
label4.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelModifiedObject.Location = new Point(344, 156);
|
||||
labelModifiedObject.Name = "labelModifiedObject";
|
||||
labelModifiedObject.Size = new Size(94, 23);
|
||||
labelModifiedObject.TabIndex = 8;
|
||||
labelModifiedObject.Text = "Продвинутый";
|
||||
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelModifiedObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// label3
|
||||
// labelSimpleObject
|
||||
//
|
||||
label3.BorderStyle = BorderStyle.FixedSingle;
|
||||
label3.Location = new Point(238, 156);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(100, 23);
|
||||
label3.TabIndex = 7;
|
||||
label3.Text = "Простой";
|
||||
label3.TextAlign = ContentAlignment.MiddleCenter;
|
||||
label3.MouseDown += LabelObject_MouseDown;
|
||||
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimpleObject.Location = new Point(238, 156);
|
||||
labelSimpleObject.Name = "labelSimpleObject";
|
||||
labelSimpleObject.Size = new Size(100, 23);
|
||||
labelSimpleObject.TabIndex = 7;
|
||||
labelSimpleObject.Text = "Простой";
|
||||
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
@ -123,6 +124,7 @@
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new Size(33, 32);
|
||||
panelPurple.TabIndex = 1;
|
||||
panelPurple.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
@ -131,14 +133,16 @@
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(33, 32);
|
||||
panelBlack.TabIndex = 1;
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
panelGray.BackColor = Color.Silver;
|
||||
panelGray.BackColor = Color.Gray;
|
||||
panelGray.Location = new Point(59, 70);
|
||||
panelGray.Name = "panelGray";
|
||||
panelGray.Size = new Size(33, 32);
|
||||
panelGray.TabIndex = 1;
|
||||
panelGray.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
@ -147,6 +151,7 @@
|
||||
panelWhite.Name = "panelWhite";
|
||||
panelWhite.Size = new Size(33, 32);
|
||||
panelWhite.TabIndex = 1;
|
||||
panelWhite.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
@ -155,6 +160,7 @@
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(33, 32);
|
||||
panelYellow.TabIndex = 1;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
@ -163,14 +169,16 @@
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(33, 32);
|
||||
panelBlue.TabIndex = 1;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
panelGreen.BackColor = Color.Lime;
|
||||
panelGreen.BackColor = Color.Green;
|
||||
panelGreen.Location = new Point(59, 32);
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new Size(33, 32);
|
||||
panelGreen.TabIndex = 1;
|
||||
panelGreen.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
@ -179,6 +187,7 @@
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(33, 32);
|
||||
panelRed.TabIndex = 0;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
//
|
||||
// checkBoxTent
|
||||
//
|
||||
@ -238,48 +247,56 @@
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Скорость:";
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
panelObject.AllowDrop = true;
|
||||
panelObject.Controls.Add(pictureBoxObject);
|
||||
panelObject.Controls.Add(labelAdditionalColor);
|
||||
panelObject.Controls.Add(labelColor);
|
||||
panelObject.Location = new Point(462, 12);
|
||||
panelObject.Name = "panelObject";
|
||||
panelObject.Size = new Size(214, 175);
|
||||
panelObject.TabIndex = 2;
|
||||
panelObject.DragDrop += PanelObject_DragDrop;
|
||||
panelObject.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(13, 54);
|
||||
pictureBoxObject.Location = new Point(13, 50);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(188, 95);
|
||||
pictureBoxObject.TabIndex = 1;
|
||||
pictureBoxObject.Size = new Size(188, 122);
|
||||
pictureBoxObject.TabIndex = 10;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// panel9
|
||||
// labelAdditionalColor
|
||||
//
|
||||
panel9.AllowDrop = true;
|
||||
panel9.Controls.Add(label6);
|
||||
panel9.Controls.Add(label5);
|
||||
panel9.Controls.Add(pictureBoxObject);
|
||||
panel9.Location = new Point(462, 12);
|
||||
panel9.Name = "panel9";
|
||||
panel9.Size = new Size(221, 160);
|
||||
panel9.TabIndex = 2;
|
||||
labelAdditionalColor.AllowDrop = true;
|
||||
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdditionalColor.Location = new Point(107, 9);
|
||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||
labelAdditionalColor.Size = new Size(94, 38);
|
||||
labelAdditionalColor.TabIndex = 9;
|
||||
labelAdditionalColor.Text = "Доп. цвет";
|
||||
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAdditionalColor.DragDrop += labelColor_DragDrop;
|
||||
labelAdditionalColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// label6
|
||||
// labelColor
|
||||
//
|
||||
label6.BorderStyle = BorderStyle.FixedSingle;
|
||||
label6.Location = new Point(107, 9);
|
||||
label6.Name = "label6";
|
||||
label6.Size = new Size(94, 38);
|
||||
label6.TabIndex = 9;
|
||||
label6.Text = "Доп. цвет";
|
||||
label6.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.BorderStyle = BorderStyle.FixedSingle;
|
||||
label5.Location = new Point(13, 9);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(88, 38);
|
||||
label5.TabIndex = 8;
|
||||
label5.Text = "Цвет";
|
||||
label5.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelColor.AllowDrop = true;
|
||||
labelColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelColor.Location = new Point(13, 9);
|
||||
labelColor.Name = "labelColor";
|
||||
labelColor.Size = new Size(88, 38);
|
||||
labelColor.TabIndex = 8;
|
||||
labelColor.Text = "Цвет";
|
||||
labelColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelColor.DragDrop += labelColor_DragDrop;
|
||||
labelColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
buttonOk.Location = new Point(475, 185);
|
||||
buttonOk.Location = new Point(475, 193);
|
||||
buttonOk.Name = "buttonOk";
|
||||
buttonOk.Size = new Size(75, 23);
|
||||
buttonOk.TabIndex = 3;
|
||||
@ -287,23 +304,23 @@
|
||||
buttonOk.UseVisualStyleBackColor = true;
|
||||
buttonOk.Click += buttonOk_Click;
|
||||
//
|
||||
// button2
|
||||
// buttonCancel
|
||||
//
|
||||
button2.Location = new Point(588, 185);
|
||||
button2.Name = "button2";
|
||||
button2.Size = new Size(75, 23);
|
||||
button2.TabIndex = 4;
|
||||
button2.Text = "Отмена";
|
||||
button2.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Location = new Point(588, 193);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.TabIndex = 4;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormTruckConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(700, 225);
|
||||
Controls.Add(button2);
|
||||
ClientSize = new Size(690, 227);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonOk);
|
||||
Controls.Add(panel9);
|
||||
Controls.Add(panelObject);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormTruckConfig";
|
||||
Text = "Создание объекта";
|
||||
@ -312,8 +329,8 @@
|
||||
groupBox2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||
panelObject.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||
panel9.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -335,13 +352,13 @@
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private Label label4;
|
||||
private Label label3;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Panel panel9;
|
||||
private Label label6;
|
||||
private Label label5;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private Panel panelObject;
|
||||
private Label labelAdditionalColor;
|
||||
private Label labelColor;
|
||||
private Button buttonOk;
|
||||
private Button button2;
|
||||
private Button buttonCancel;
|
||||
private PictureBox pictureBoxObject;
|
||||
}
|
||||
}
|
@ -28,22 +28,22 @@ namespace Project_DumpTruck
|
||||
public FormTruckConfig()
|
||||
{
|
||||
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;
|
||||
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;
|
||||
|
||||
// TODO buttonCancel.Click with lambda
|
||||
buttonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовать машину
|
||||
/// </summary>
|
||||
private void DrawCar()
|
||||
private void DrawTruck()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
@ -75,8 +75,12 @@ namespace Project_DumpTruck
|
||||
/// <param name="e"></param>
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||
DragDropEffects.Move | DragDropEffects.Copy);
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -96,6 +100,18 @@ namespace Project_DumpTruck
|
||||
}
|
||||
}
|
||||
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
@ -117,9 +133,30 @@ namespace Project_DumpTruck
|
||||
pictureBoxObject.Height);
|
||||
break;
|
||||
}
|
||||
DrawCar();
|
||||
DrawTruck();
|
||||
}
|
||||
|
||||
private void labelColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_truck == null)
|
||||
return;
|
||||
|
||||
((Label)sender).BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
switch (((Label)sender).Name)
|
||||
{
|
||||
case "labelColor":
|
||||
_truck.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "labelAdditionalColor":
|
||||
if (!(_truck is DrawningDumpTruck))
|
||||
{
|
||||
return;
|
||||
}
|
||||
(_truck as DrawningDumpTruck).SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawTruck();
|
||||
}
|
||||
// TODO Реализовать логику смены цветов: основного и дополнительного(для продвинутого объекта)
|
||||
|
||||
/// <summary>
|
||||
/// Добавление машины
|
||||
|
Loading…
Reference in New Issue
Block a user