PIbd-23 Vrazhkin S.A. Work5 #5

Closed
kirin wants to merge 2 commits from lab5 into lab4
3 changed files with 596 additions and 0 deletions
Showing only changes of commit 1834031847 - Show all commits

350
lab1/FormLocoConfig.Designer.cs generated Normal file
View 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
View 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) {
Review

Логика 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
View 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>