PIbd-23 Vrazhkin S.A. Work5 #5
@ -4,15 +4,24 @@ namespace ElectricLocomotive;
|
||||
|
||||
public class DrawingElectricLocomotiv : DrawingLocomotiv
|
||||
{
|
||||
public DrawingElectricLocomotiv(int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor) : base(speed, weight, width,
|
||||
private bool isBattery;
|
||||
private bool isRoga;
|
||||
public DrawingElectricLocomotiv(bool isBattery, bool isRoga, int speed, double weight, int width, int height, Color mainColor, Color dopColor, Color batteryColor, Color rogaColor) : base(speed, weight, width,
|
||||
height, mainColor, dopColor)
|
||||
{
|
||||
this.isBattery = isBattery;
|
||||
this.isRoga = isRoga;
|
||||
if (EntityLocomotiv != null)
|
||||
{
|
||||
EntityLocomotiv = new EntityElectricLocomotiv(speed, weight, batteryColor, rogaColor, mainColor, dopColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeAddColor(Color col)
|
||||
{
|
||||
((EntityElectricLocomotiv)EntityLocomotiv).BatteryColor = col;
|
||||
((EntityElectricLocomotiv)EntityLocomotiv).RogaColor = col;
|
||||
}
|
||||
public override void DrawLoco(Graphics g)
|
||||
{
|
||||
if (EntityLocomotiv == null) return;
|
||||
@ -20,11 +29,16 @@ public class DrawingElectricLocomotiv : DrawingLocomotiv
|
||||
if (EntityLocomotiv is not EntityElectricLocomotiv electricLocomotiv) return;
|
||||
SolidBrush batteryBrush = new(electricLocomotiv.BatteryColor);
|
||||
Pen rogaPen = new(electricLocomotiv.RogaColor);
|
||||
//Roga
|
||||
g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15));
|
||||
g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY));
|
||||
//battery
|
||||
Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) };
|
||||
g.FillPolygon(batteryBrush, batteryPoints);
|
||||
if (this.isRoga)
|
||||
{
|
||||
g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2, _startPosY + 30), new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15));
|
||||
g.DrawLine(rogaPen, new Point(_startPosX + _vehicleWidth / 2 + 10, _startPosY + 15), new Point(_startPosX + _vehicleWidth / 2, _startPosY));
|
||||
}
|
||||
|
||||
if (this.isBattery)
|
||||
{
|
||||
Point[] batteryPoints = { new Point(_startPosX + _vehicleWidth - 10,_startPosY + _vehicleHeight - 25), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 20), new Point(_startPosX + _vehicleWidth, _startPosY + _vehicleHeight - 55), new Point(_startPosX + _vehicleWidth - 10, _startPosY + _vehicleHeight - 50) };
|
||||
g.FillPolygon(batteryBrush, batteryPoints);
|
||||
}
|
||||
}
|
||||
}
|
@ -41,6 +41,14 @@ namespace ElectricLocomotive
|
||||
_pictureHeight = height;
|
||||
EntityLocomotiv = new EntityLocomotiv(speed, weight, mainColor, dopColor);
|
||||
}
|
||||
|
||||
public void ChangeColor(Color col)
|
||||
{
|
||||
if (EntityLocomotiv == null)
|
||||
return;
|
||||
EntityLocomotiv.ColorBody = col;
|
||||
EntityLocomotiv.ColorWindow = col;
|
||||
}
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityLocomotiv == null)
|
||||
@ -96,6 +104,11 @@ namespace ElectricLocomotive
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
|
||||
{
|
||||
_pictureHeight = pictureBoxHeight;
|
||||
_pictureWidth = pictureBoxWidth;
|
||||
}
|
||||
public virtual void DrawLoco(Graphics g)
|
||||
{
|
||||
if (EntityLocomotiv == null) return;
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
public class EntityElectricLocomotiv : EntityLocomotiv
|
||||
{
|
||||
public Color BatteryColor { get; private set; }
|
||||
public Color RogaColor { get; private set; }
|
||||
public Color BatteryColor { get; set; }
|
||||
|
||||
public Color RogaColor { get; set; }
|
||||
public EntityElectricLocomotiv(int speed,double weight, Color batteryColor, Color rogaColor, Color mainColor, Color dopColor) : base(speed, weight, mainColor, dopColor)
|
||||
{
|
||||
BatteryColor = batteryColor;
|
||||
|
@ -9,8 +9,8 @@ namespace ElectricLocomotive
|
||||
{
|
||||
public class EntityLocomotiv
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public int Speed { get; set; }
|
||||
public double Weight { get; set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public Color ColorBody = Color.Black;
|
||||
public Color ColorWindow = Color.Blue;
|
||||
|
350
lab1/FormLocoConfig.Designer.cs
generated
Normal file
350
lab1/FormLocoConfig.Designer.cs
generated
Normal file
@ -0,0 +1,350 @@
|
||||
namespace ElectricLocomotive {
|
||||
partial class FormLocoConfig {
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (disposing && (components != null)) {
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent() {
|
||||
mainGroupBox = new GroupBox();
|
||||
checkBoxBattery = new CheckBox();
|
||||
checkBoxRoga = new CheckBox();
|
||||
labelAdvanced = new Label();
|
||||
labelSimple = new Label();
|
||||
groupBoxColors = new GroupBox();
|
||||
panelPurple = new Panel();
|
||||
panelYellow = new Panel();
|
||||
panelBlack = new Panel();
|
||||
panelBlue = new Panel();
|
||||
panelGray = new Panel();
|
||||
panelGreen = new Panel();
|
||||
panelWhite = new Panel();
|
||||
panelRed = new Panel();
|
||||
numericUpDownWeight = new NumericUpDown();
|
||||
numericUpDownSpeed = new NumericUpDown();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
rightPanel = new Panel();
|
||||
labelAddColor = new Label();
|
||||
labelColor = new Label();
|
||||
pictureBox = new PictureBox();
|
||||
buttonAdd = new Button();
|
||||
buttonCancel = new Button();
|
||||
mainGroupBox.SuspendLayout();
|
||||
groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||
rightPanel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// mainGroupBox
|
||||
//
|
||||
mainGroupBox.Controls.Add(checkBoxBattery);
|
||||
mainGroupBox.Controls.Add(checkBoxRoga);
|
||||
mainGroupBox.Controls.Add(labelAdvanced);
|
||||
mainGroupBox.Controls.Add(labelSimple);
|
||||
mainGroupBox.Controls.Add(groupBoxColors);
|
||||
mainGroupBox.Controls.Add(numericUpDownWeight);
|
||||
mainGroupBox.Controls.Add(numericUpDownSpeed);
|
||||
mainGroupBox.Controls.Add(label2);
|
||||
mainGroupBox.Controls.Add(label1);
|
||||
mainGroupBox.Location = new Point(12, 12);
|
||||
mainGroupBox.Name = "mainGroupBox";
|
||||
mainGroupBox.Size = new Size(656, 289);
|
||||
mainGroupBox.TabIndex = 0;
|
||||
mainGroupBox.TabStop = false;
|
||||
mainGroupBox.Text = "Параметры";
|
||||
//
|
||||
// checkBoxBattery
|
||||
//
|
||||
checkBoxBattery.AutoSize = true;
|
||||
checkBoxBattery.Location = new Point(25, 194);
|
||||
checkBoxBattery.Name = "checkBoxBattery";
|
||||
checkBoxBattery.Size = new Size(215, 24);
|
||||
checkBoxBattery.TabIndex = 8;
|
||||
checkBoxBattery.Text = "Признак наличия батарей";
|
||||
checkBoxBattery.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxRoga
|
||||
//
|
||||
checkBoxRoga.AutoSize = true;
|
||||
checkBoxRoga.Location = new Point(25, 150);
|
||||
checkBoxRoga.Name = "checkBoxRoga";
|
||||
checkBoxRoga.Size = new Size(199, 24);
|
||||
checkBoxRoga.TabIndex = 7;
|
||||
checkBoxRoga.Text = "Признак наличия рогов";
|
||||
checkBoxRoga.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelAdvanced
|
||||
//
|
||||
labelAdvanced.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdvanced.Location = new Point(498, 231);
|
||||
labelAdvanced.Name = "labelAdvanced";
|
||||
labelAdvanced.Size = new Size(141, 44);
|
||||
labelAdvanced.TabIndex = 6;
|
||||
labelAdvanced.Text = "Продвинутый";
|
||||
labelAdvanced.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// labelSimple
|
||||
//
|
||||
labelSimple.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelSimple.Location = new Point(323, 231);
|
||||
labelSimple.Name = "labelSimple";
|
||||
labelSimple.Size = new Size(141, 44);
|
||||
labelSimple.TabIndex = 5;
|
||||
labelSimple.Text = "Простой";
|
||||
labelSimple.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelSimple.MouseDown += labelSimple_MouseDown;
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
groupBoxColors.Controls.Add(panelPurple);
|
||||
groupBoxColors.Controls.Add(panelYellow);
|
||||
groupBoxColors.Controls.Add(panelBlack);
|
||||
groupBoxColors.Controls.Add(panelBlue);
|
||||
groupBoxColors.Controls.Add(panelGray);
|
||||
groupBoxColors.Controls.Add(panelGreen);
|
||||
groupBoxColors.Controls.Add(panelWhite);
|
||||
groupBoxColors.Controls.Add(panelRed);
|
||||
groupBoxColors.Location = new Point(323, 26);
|
||||
groupBoxColors.Name = "groupBoxColors";
|
||||
groupBoxColors.Size = new Size(316, 192);
|
||||
groupBoxColors.TabIndex = 4;
|
||||
groupBoxColors.TabStop = false;
|
||||
groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
panelPurple.BackColor = Color.Purple;
|
||||
panelPurple.Location = new Point(239, 114);
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new Size(60, 56);
|
||||
panelPurple.TabIndex = 3;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = Color.Yellow;
|
||||
panelYellow.Location = new Point(239, 38);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(60, 56);
|
||||
panelYellow.TabIndex = 1;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
panelBlack.BackColor = Color.Black;
|
||||
panelBlack.Location = new Point(159, 114);
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(60, 56);
|
||||
panelBlack.TabIndex = 4;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = Color.Navy;
|
||||
panelBlue.Location = new Point(159, 38);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(60, 56);
|
||||
panelBlue.TabIndex = 1;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
panelGray.BackColor = Color.Gray;
|
||||
panelGray.Location = new Point(81, 114);
|
||||
panelGray.Name = "panelGray";
|
||||
panelGray.Size = new Size(60, 56);
|
||||
panelGray.TabIndex = 5;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
panelGreen.BackColor = Color.Green;
|
||||
panelGreen.Location = new Point(81, 38);
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new Size(60, 56);
|
||||
panelGreen.TabIndex = 1;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
panelWhite.BackColor = Color.White;
|
||||
panelWhite.Location = new Point(6, 114);
|
||||
panelWhite.Name = "panelWhite";
|
||||
panelWhite.Size = new Size(60, 56);
|
||||
panelWhite.TabIndex = 2;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = Color.FromArgb(192, 0, 0);
|
||||
panelRed.Location = new Point(6, 38);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(60, 56);
|
||||
panelRed.TabIndex = 0;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(113, 82);
|
||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(75, 27);
|
||||
numericUpDownWeight.TabIndex = 3;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(113, 42);
|
||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(75, 27);
|
||||
numericUpDownSpeed.TabIndex = 2;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(19, 82);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(33, 20);
|
||||
label2.TabIndex = 1;
|
||||
label2.Text = "Вес";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(19, 42);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(73, 20);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Скорость";
|
||||
//
|
||||
// rightPanel
|
||||
//
|
||||
rightPanel.AllowDrop = true;
|
||||
rightPanel.Controls.Add(labelAddColor);
|
||||
rightPanel.Controls.Add(labelColor);
|
||||
rightPanel.Controls.Add(pictureBox);
|
||||
rightPanel.Location = new Point(689, 21);
|
||||
rightPanel.Name = "rightPanel";
|
||||
rightPanel.Size = new Size(348, 234);
|
||||
rightPanel.TabIndex = 1;
|
||||
rightPanel.DragDrop += rightPanel_DragDrop;
|
||||
rightPanel.DragEnter += rightPanel_DragEnter;
|
||||
//
|
||||
// labelAddColor
|
||||
//
|
||||
labelAddColor.AllowDrop = true;
|
||||
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAddColor.Location = new Point(184, 12);
|
||||
labelAddColor.Name = "labelAddColor";
|
||||
labelAddColor.Size = new Size(149, 40);
|
||||
labelAddColor.TabIndex = 2;
|
||||
labelAddColor.Text = "Доп. Цвет";
|
||||
labelAddColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAddColor.DragDrop += labelAddColor_DragDrop;
|
||||
labelAddColor.DragEnter += labelAddColor_DragEnter;
|
||||
//
|
||||
// labelColor
|
||||
//
|
||||
labelColor.AllowDrop = true;
|
||||
labelColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelColor.Location = new Point(16, 12);
|
||||
labelColor.Name = "labelColor";
|
||||
labelColor.Size = new Size(149, 40);
|
||||
labelColor.TabIndex = 1;
|
||||
labelColor.Text = "Цвет";
|
||||
labelColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelColor.DragDrop += labelColor_DragDrop;
|
||||
labelColor.DragEnter += labelColor_DragEnter;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Location = new Point(16, 55);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(317, 165);
|
||||
pictureBox.TabIndex = 0;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(689, 266);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(165, 35);
|
||||
buttonAdd.TabIndex = 2;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(872, 266);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(165, 35);
|
||||
buttonCancel.TabIndex = 3;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormLocoConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1053, 313);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(rightPanel);
|
||||
Controls.Add(mainGroupBox);
|
||||
Name = "FormLocoConfig";
|
||||
Text = "Создание объекта";
|
||||
mainGroupBox.ResumeLayout(false);
|
||||
mainGroupBox.PerformLayout();
|
||||
groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||
rightPanel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox mainGroupBox;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelSimple;
|
||||
private GroupBox groupBoxColors;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private Label labelAdvanced;
|
||||
private Panel panelYellow;
|
||||
private Panel panelBlue;
|
||||
private Panel panelGreen;
|
||||
private Panel panelRed;
|
||||
private Panel panelPurple;
|
||||
private Panel panelBlack;
|
||||
private Panel panelGray;
|
||||
private Panel panelWhite;
|
||||
private CheckBox checkBoxBattery;
|
||||
private CheckBox checkBoxRoga;
|
||||
private Panel rightPanel;
|
||||
private Label labelAddColor;
|
||||
private Label labelColor;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonAdd;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
126
lab1/FormLocoConfig.cs
Normal file
126
lab1/FormLocoConfig.cs
Normal file
@ -0,0 +1,126 @@
|
||||
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;
|
||||
|
||||
namespace ElectricLocomotive {
|
||||
public partial class FormLocoConfig : Form {
|
||||
DrawingLocomotiv? _loco = null;
|
||||
private event Action<DrawingLocomotiv>? EventAddLoco;
|
||||
public void AddEvent(Action<DrawingLocomotiv> ev) {
|
||||
if (EventAddLoco == null) {
|
||||
EventAddLoco = ev;
|
||||
}
|
||||
else {
|
||||
EventAddLoco += ev;
|
||||
}
|
||||
}
|
||||
public FormLocoConfig() {
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
panelGray.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
labelSimple.MouseDown += LabelObject_MouseDown;
|
||||
labelAdvanced.MouseDown += LabelObject_MouseDown;
|
||||
buttonCancel.Click += (s, e) => Close();
|
||||
}
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e) {
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
||||
DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e) {
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void DrawLoco() {
|
||||
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_loco?.SetPosition(5, 5);
|
||||
_loco?.DrawLoco(gr);
|
||||
pictureBox.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
private void labelSimple_MouseDown(object sender, MouseEventArgs e) {
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
||||
DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void rightPanel_DragEnter(object sender, DragEventArgs e) {
|
||||
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) {
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else {
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void rightPanel_DragDrop(object sender, DragEventArgs e) {
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString()) {
|
||||
case "labelSimple":
|
||||
_loco = new DrawingLocomotiv((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, pictureBox.Width,
|
||||
pictureBox.Height, Color.Black, Color.Yellow);
|
||||
break;
|
||||
case "labelAdvanced":
|
||||
_loco = new DrawingElectricLocomotiv(checkBoxRoga.Checked, checkBoxBattery.Checked,
|
||||
(int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, pictureBox.Width,
|
||||
pictureBox.Height, Color.Black, Color.Yellow, Color.Aqua, Color.Black);
|
||||
break;
|
||||
}
|
||||
labelColor.BackColor = Color.Empty;
|
||||
labelAddColor.BackColor = Color.Empty;
|
||||
DrawLoco();
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e) {
|
||||
EventAddLoco?.Invoke(_loco);
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
private void labelColor_DragEnter(object sender, DragEventArgs e) {
|
||||
if (e.Data.GetDataPresent(typeof(Color))) {
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else {
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void labelColor_DragDrop(object sender, DragEventArgs e) {
|
||||
if (_loco == null)
|
||||
return;
|
||||
labelColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
_loco.ChangeColor(labelColor.BackColor);
|
||||
DrawLoco();
|
||||
}
|
||||
|
||||
private void labelAddColor_DragEnter(object sender, DragEventArgs e) {
|
||||
eegov
commented
Логика DragEnter основного цвета идентична логике DragEnter дополнительного цвета и отдельная обработка тут не нужна Логика DragEnter основного цвета идентична логике DragEnter дополнительного цвета и отдельная обработка тут не нужна
|
||||
if (e.Data.GetDataPresent(typeof(Color))) {
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else {
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void labelAddColor_DragDrop(object sender, DragEventArgs e) {
|
||||
if ((_loco == null) || (_loco is DrawingElectricLocomotiv == false))
|
||||
return;
|
||||
labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color));
|
||||
((DrawingElectricLocomotiv)_loco).ChangeAddColor(labelAddColor.BackColor);
|
||||
DrawLoco();
|
||||
}
|
||||
}
|
||||
}
|
120
lab1/FormLocoConfig.resx
Normal file
120
lab1/FormLocoConfig.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -43,7 +43,7 @@ namespace ElectricLocomotive {
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
dopColor = dialog.Color;
|
||||
|
||||
_drawingLocomotiv = new DrawingElectricLocomotiv(random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor, batteryColor, rogaColor);
|
||||
_drawingLocomotiv = new DrawingElectricLocomotiv(true, true, random.Next(100, 300), random.Next(1000, 3000), locoBox.Width, locoBox.Height, color, dopColor, batteryColor, rogaColor);
|
||||
_drawingLocomotiv.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
@ -30,17 +30,22 @@ public partial class FormLocomotivCollection : Form {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
FormLocomotiv form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK) {
|
||||
if (obj + form.SelectedLocomotiv) {
|
||||
FormLocoConfig form = new();
|
||||
form.Show();
|
||||
Action<DrawingLocomotiv>? monorailDelegate = new((m) => {
|
||||
bool q = (obj + m);
|
||||
if (q)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
m.ChangePictureBoxSize(collectionPictureBox.Width, collectionPictureBox.Height);
|
||||
collectionPictureBox.Image = obj.ShowLocos();
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
form.AddEvent(monorailDelegate);
|
||||
}
|
||||
private void deleteLoco_Click(object sender, EventArgs e) {
|
||||
if (storageListBox.SelectedIndex == -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user
В классах-сущностях требовалось прописать методы для смены основного и дополнительного цветов