Create FormCinfig 4 lab

This commit is contained in:
ekallin 2023-11-02 19:25:09 +04:00
parent 7051e1850d
commit 21b20cb0c9
2 changed files with 421 additions and 2 deletions

View File

@ -28,19 +28,346 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxObjectParameters = new System.Windows.Forms.GroupBox();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.labelSpeed = new System.Windows.Forms.Label();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.labelModifiedObject = new System.Windows.Forms.Label();
this.checkBoxHorns = new System.Windows.Forms.CheckBox();
this.checkBoxSeifBatteries = new System.Windows.Forms.CheckBox();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel3 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel4 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel5 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel6 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel7 = new System.Windows.Forms.FlowLayoutPanel();
this.flowLayoutPanel8 = new System.Windows.Forms.FlowLayoutPanel();
this.panelObject = new System.Windows.Forms.Panel();
this.labelAddColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.groupBoxObjectParameters.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxObjectParameters
//
this.groupBoxObjectParameters.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBoxObjectParameters.Controls.Add(this.numericUpDownWeight);
this.groupBoxObjectParameters.Controls.Add(this.numericUpDownSpeed);
this.groupBoxObjectParameters.Controls.Add(this.checkBoxSeifBatteries);
this.groupBoxObjectParameters.Controls.Add(this.checkBoxHorns);
this.groupBoxObjectParameters.Controls.Add(this.labelModifiedObject);
this.groupBoxObjectParameters.Controls.Add(this.labelSimpleObject);
this.groupBoxObjectParameters.Controls.Add(this.labelWeight);
this.groupBoxObjectParameters.Controls.Add(this.labelSpeed);
this.groupBoxObjectParameters.Controls.Add(this.groupBoxColors);
this.groupBoxObjectParameters.Location = new System.Drawing.Point(7, 12);
this.groupBoxObjectParameters.Name = "groupBoxObjectParameters";
this.groupBoxObjectParameters.Size = new System.Drawing.Size(792, 395);
this.groupBoxObjectParameters.TabIndex = 0;
this.groupBoxObjectParameters.TabStop = false;
this.groupBoxObjectParameters.Text = "Параметры";
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.flowLayoutPanel5);
this.groupBoxColors.Controls.Add(this.flowLayoutPanel6);
this.groupBoxColors.Controls.Add(this.flowLayoutPanel7);
this.groupBoxColors.Controls.Add(this.flowLayoutPanel8);
this.groupBoxColors.Controls.Add(this.flowLayoutPanel4);
this.groupBoxColors.Controls.Add(this.flowLayoutPanel3);
this.groupBoxColors.Controls.Add(this.flowLayoutPanel2);
this.groupBoxColors.Controls.Add(this.flowLayoutPanel1);
this.groupBoxColors.Location = new System.Drawing.Point(390, 22);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(378, 176);
this.groupBoxColors.TabIndex = 0;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(19, 36);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(73, 20);
this.labelSpeed.TabIndex = 1;
this.labelSpeed.Text = "Скорость";
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(19, 94);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(33, 20);
this.labelWeight.TabIndex = 2;
this.labelWeight.Text = "Вес";
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(390, 239);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(113, 44);
this.labelSimpleObject.TabIndex = 3;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelModifiedObject
//
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifiedObject.Location = new System.Drawing.Point(655, 239);
this.labelModifiedObject.Name = "labelModifiedObject";
this.labelModifiedObject.Size = new System.Drawing.Size(113, 44);
this.labelModifiedObject.TabIndex = 4;
this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// checkBoxHorns
//
this.checkBoxHorns.AutoSize = true;
this.checkBoxHorns.Location = new System.Drawing.Point(19, 174);
this.checkBoxHorns.Name = "checkBoxHorns";
this.checkBoxHorns.Size = new System.Drawing.Size(199, 24);
this.checkBoxHorns.TabIndex = 5;
this.checkBoxHorns.Text = "Признак наличия рогов";
this.checkBoxHorns.UseVisualStyleBackColor = true;
//
// checkBoxSeifBatteries
//
this.checkBoxSeifBatteries.AutoSize = true;
this.checkBoxSeifBatteries.Location = new System.Drawing.Point(19, 259);
this.checkBoxSeifBatteries.Name = "checkBoxSeifBatteries";
this.checkBoxSeifBatteries.Size = new System.Drawing.Size(297, 24);
this.checkBoxSeifBatteries.TabIndex = 6;
this.checkBoxSeifBatteries.Text = "Признак наличия батарейного отсека";
this.checkBoxSeifBatteries.UseVisualStyleBackColor = true;
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(108, 34);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27);
this.numericUpDownSpeed.TabIndex = 7;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(108, 92);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27);
this.numericUpDownWeight.TabIndex = 8;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
this.flowLayoutPanel1.Location = new System.Drawing.Point(55, 35);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel1.TabIndex = 0;
//
// flowLayoutPanel2
//
this.flowLayoutPanel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.flowLayoutPanel2.Location = new System.Drawing.Point(132, 35);
this.flowLayoutPanel2.Name = "flowLayoutPanel2";
this.flowLayoutPanel2.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel2.TabIndex = 1;
//
// flowLayoutPanel3
//
this.flowLayoutPanel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
this.flowLayoutPanel3.Location = new System.Drawing.Point(207, 35);
this.flowLayoutPanel3.Name = "flowLayoutPanel3";
this.flowLayoutPanel3.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel3.TabIndex = 1;
//
// flowLayoutPanel4
//
this.flowLayoutPanel4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.flowLayoutPanel4.Location = new System.Drawing.Point(281, 35);
this.flowLayoutPanel4.Name = "flowLayoutPanel4";
this.flowLayoutPanel4.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel4.TabIndex = 1;
//
// flowLayoutPanel5
//
this.flowLayoutPanel5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.flowLayoutPanel5.Location = new System.Drawing.Point(281, 110);
this.flowLayoutPanel5.Name = "flowLayoutPanel5";
this.flowLayoutPanel5.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel5.TabIndex = 3;
//
// flowLayoutPanel6
//
this.flowLayoutPanel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.flowLayoutPanel6.Location = new System.Drawing.Point(207, 110);
this.flowLayoutPanel6.Name = "flowLayoutPanel6";
this.flowLayoutPanel6.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel6.TabIndex = 4;
//
// flowLayoutPanel7
//
this.flowLayoutPanel7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.flowLayoutPanel7.Location = new System.Drawing.Point(132, 110);
this.flowLayoutPanel7.Name = "flowLayoutPanel7";
this.flowLayoutPanel7.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel7.TabIndex = 5;
//
// flowLayoutPanel8
//
this.flowLayoutPanel8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.flowLayoutPanel8.Location = new System.Drawing.Point(55, 110);
this.flowLayoutPanel8.Name = "flowLayoutPanel8";
this.flowLayoutPanel8.Size = new System.Drawing.Size(40, 40);
this.flowLayoutPanel8.TabIndex = 2;
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Controls.Add(this.labelAddColor);
this.panelObject.Controls.Add(this.labelColor);
this.panelObject.Location = new System.Drawing.Point(812, 25);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(392, 300);
this.panelObject.TabIndex = 1;
//
// labelAddColor
//
this.labelAddColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAddColor.Location = new System.Drawing.Point(260, 21);
this.labelAddColor.Name = "labelAddColor";
this.labelAddColor.Size = new System.Drawing.Size(113, 44);
this.labelAddColor.TabIndex = 6;
this.labelAddColor.Text = "Доп. Цвет";
this.labelAddColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelColor
//
this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelColor.Location = new System.Drawing.Point(19, 21);
this.labelColor.Name = "labelColor";
this.labelColor.Size = new System.Drawing.Size(113, 44);
this.labelColor.TabIndex = 5;
this.labelColor.Text = "Цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button1
//
this.button1.Location = new System.Drawing.Point(813, 341);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(131, 49);
this.button1.TabIndex = 2;
this.button1.Text = "Добавить";
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.Location = new System.Drawing.Point(1072, 341);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(131, 49);
this.button2.TabIndex = 3;
this.button2.Text = "Отмена";
this.button2.UseVisualStyleBackColor = true;
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(19, 83);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(354, 198);
this.pictureBoxObject.TabIndex = 7;
this.pictureBoxObject.TabStop = false;
//
// FormLocomotiveConfig // FormLocomotiveConfig
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1216, 551); this.ClientSize = new System.Drawing.Size(1219, 419);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxObjectParameters);
this.Name = "FormLocomotiveConfig"; this.Name = "FormLocomotiveConfig";
this.Text = "FormLocomotiveConfig"; this.Text = "FormLocomotiveConfig";
this.groupBoxObjectParameters.ResumeLayout(false);
this.groupBoxObjectParameters.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBoxObjectParameters;
private Label labelModifiedObject;
private Label labelSimpleObject;
private Label labelWeight;
private Label labelSpeed;
private GroupBox groupBoxColors;
private CheckBox checkBoxSeifBatteries;
private CheckBox checkBoxHorns;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private FlowLayoutPanel flowLayoutPanel5;
private FlowLayoutPanel flowLayoutPanel6;
private FlowLayoutPanel flowLayoutPanel7;
private FlowLayoutPanel flowLayoutPanel8;
private FlowLayoutPanel flowLayoutPanel4;
private FlowLayoutPanel flowLayoutPanel3;
private FlowLayoutPanel flowLayoutPanel2;
private FlowLayoutPanel flowLayoutPanel1;
private Panel panelObject;
private PictureBox pictureBoxObject;
private Label labelAddColor;
private Label labelColor;
private Button button1;
private Button button2;
} }
} }

View File

@ -1,4 +1,5 @@
using System; using ProjectElectricLocomotive.DrawingObjects;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -12,9 +13,100 @@ namespace ProjectElectricLocomotive
{ {
public partial class FormLocomotiveConfig : Form public partial class FormLocomotiveConfig : Form
{ {
/// <summary>
/// Делегат для передачи объекта-локомотив
/// </summary>
/// <param name="loco"></param>
public delegate void LocoDelegate(DrawingLocomotive loco);
/// <summary>
/// Переменная-выбранный локомотив
/// </summary>
DrawingLocomotive? _loco = null;
/// <summary>
/// Событие
/// </summary>
private event LocoDelegate? EventAddLoco;
public FormLocomotiveConfig() public FormLocomotiveConfig()
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// Отрисовать Loco
/// </summary>
private void DrawLoco()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_loco?.SetPosition(5, 5);
_loco?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_loco = new DrawingLocomotive(
(int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value,
Color.White,
pictureBoxObject.Width,
pictureBoxObject.Height
);
break;
case "labelModifiedObject":
_loco = new DrawingElectricLocomotive(
(int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value,
Color.White,
Color.Black,
checkBoxHorns.Checked,
checkBoxSeifBatteries.Checked,
pictureBoxObject.Width,
pictureBoxObject.Height
);
break;
}
DrawLoco();
}
} }
} }