продолжение работы над лабой

This commit is contained in:
Полина Чубыкина 2023-11-07 22:22:14 +04:00
parent 5ade5f7e08
commit b700173d7b
3 changed files with 130 additions and 125 deletions

View File

@ -48,6 +48,13 @@ namespace Sailboat
} }
private void buttonAddBoat_Click(object sender, EventArgs e) private void buttonAddBoat_Click(object sender, EventArgs e)
{
var formBoatConfig = new FormBoatConfig();
formBoatConfig.AddEvent(AddBoat);
formBoatConfig.Show();
}
private void AddBoat(DrawingBoat drawingBoat)
{ {
if (listBoxStorages.SelectedIndex == -1) if (listBoxStorages.SelectedIndex == -1)
{ {

View File

@ -38,25 +38,25 @@
this.panelGreen = new System.Windows.Forms.Panel(); this.panelGreen = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel(); this.panelRed = new System.Windows.Forms.Panel();
this.groupBoxParameters = new System.Windows.Forms.GroupBox(); this.groupBoxParameters = new System.Windows.Forms.GroupBox();
this.labelSpeed = new System.Windows.Forms.Label();
this.labelWeight = new System.Windows.Forms.Label();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.checkBoxHull = new System.Windows.Forms.CheckBox();
this.checkBoxSail = new System.Windows.Forms.CheckBox();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.labelModifiedObject = new System.Windows.Forms.Label(); this.labelModifiedObject = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel(); this.labelSimpleObject = new System.Windows.Forms.Label();
this.checkBoxSail = new System.Windows.Forms.CheckBox();
this.checkBoxHull = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.panelObject = new System.Windows.Forms.Panel();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.labelAddColor = new System.Windows.Forms.Label(); this.labelAddColor = new System.Windows.Forms.Label();
this.labelColor = new System.Windows.Forms.Label(); this.labelColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox(); this.buttonOk = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxColors.SuspendLayout(); this.groupBoxColors.SuspendLayout();
this.groupBoxParameters.SuspendLayout(); this.groupBoxParameters.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -84,6 +84,7 @@
this.panelPurple.Name = "panelPurple"; this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(50, 50); this.panelPurple.Size = new System.Drawing.Size(50, 50);
this.panelPurple.TabIndex = 7; this.panelPurple.TabIndex = 7;
this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelYellow // panelYellow
// //
@ -92,6 +93,7 @@
this.panelYellow.Name = "panelYellow"; this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(50, 50); this.panelYellow.Size = new System.Drawing.Size(50, 50);
this.panelYellow.TabIndex = 3; this.panelYellow.TabIndex = 3;
this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelBlack // panelBlack
// //
@ -100,6 +102,7 @@
this.panelBlack.Name = "panelBlack"; this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(50, 50); this.panelBlack.Size = new System.Drawing.Size(50, 50);
this.panelBlack.TabIndex = 6; this.panelBlack.TabIndex = 6;
this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelBlue // panelBlue
// //
@ -108,6 +111,7 @@
this.panelBlue.Name = "panelBlue"; this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(50, 50); this.panelBlue.Size = new System.Drawing.Size(50, 50);
this.panelBlue.TabIndex = 2; this.panelBlue.TabIndex = 2;
this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelGray // panelGray
// //
@ -116,6 +120,7 @@
this.panelGray.Name = "panelGray"; this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(50, 50); this.panelGray.Size = new System.Drawing.Size(50, 50);
this.panelGray.TabIndex = 5; this.panelGray.TabIndex = 5;
this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelWhite // panelWhite
// //
@ -124,6 +129,7 @@
this.panelWhite.Name = "panelWhite"; this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(50, 50); this.panelWhite.Size = new System.Drawing.Size(50, 50);
this.panelWhite.TabIndex = 4; this.panelWhite.TabIndex = 4;
this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelGreen // panelGreen
// //
@ -132,6 +138,7 @@
this.panelGreen.Name = "panelGreen"; this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(50, 50); this.panelGreen.Size = new System.Drawing.Size(50, 50);
this.panelGreen.TabIndex = 1; this.panelGreen.TabIndex = 1;
this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// panelRed // panelRed
// //
@ -140,6 +147,7 @@
this.panelRed.Name = "panelRed"; this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(50, 50); this.panelRed.Size = new System.Drawing.Size(50, 50);
this.panelRed.TabIndex = 0; this.panelRed.TabIndex = 0;
this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown);
// //
// groupBoxParameters // groupBoxParameters
// //
@ -159,45 +167,47 @@
this.groupBoxParameters.TabStop = false; this.groupBoxParameters.TabStop = false;
this.groupBoxParameters.Text = "Параметры"; this.groupBoxParameters.Text = "Параметры";
// //
// labelSpeed // labelModifiedObject
// //
this.labelSpeed.AutoSize = true; this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSpeed.Location = new System.Drawing.Point(25, 36); this.labelModifiedObject.Location = new System.Drawing.Point(489, 225);
this.labelSpeed.Name = "labelSpeed"; this.labelModifiedObject.Name = "labelModifiedObject";
this.labelSpeed.Size = new System.Drawing.Size(76, 20); this.labelModifiedObject.Size = new System.Drawing.Size(140, 40);
this.labelSpeed.TabIndex = 1; this.labelModifiedObject.TabIndex = 8;
this.labelSpeed.Text = "Скорость:"; this.labelModifiedObject.Text = "Продвинутый";
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
// //
// labelWeight // labelSimpleObject
// //
this.labelWeight.AutoSize = true; this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelWeight.Location = new System.Drawing.Point(25, 79); this.labelSimpleObject.Location = new System.Drawing.Point(345, 225);
this.labelWeight.Name = "labelWeight"; this.labelSimpleObject.Name = "labelSimpleObject";
this.labelWeight.Size = new System.Drawing.Size(36, 20); this.labelSimpleObject.Size = new System.Drawing.Size(140, 40);
this.labelWeight.TabIndex = 2; this.labelSimpleObject.TabIndex = 7;
this.labelWeight.Text = "Вес:"; this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
// //
// numericUpDownSpeed // checkBoxSail
// //
this.numericUpDownSpeed.Location = new System.Drawing.Point(118, 34); this.checkBoxSail.AutoSize = true;
this.numericUpDownSpeed.Maximum = new decimal(new int[] { this.checkBoxSail.Location = new System.Drawing.Point(6, 168);
1000, this.checkBoxSail.Name = "checkBoxSail";
0, this.checkBoxSail.Size = new System.Drawing.Size(169, 24);
0, this.checkBoxSail.TabIndex = 6;
0}); this.checkBoxSail.Text = "Наличие парусника";
this.numericUpDownSpeed.Minimum = new decimal(new int[] { this.checkBoxSail.UseVisualStyleBackColor = true;
100, //
0, // checkBoxHull
0, //
0}); this.checkBoxHull.AutoSize = true;
this.numericUpDownSpeed.Name = "numericUpDownSpeed"; this.checkBoxHull.Location = new System.Drawing.Point(6, 127);
this.numericUpDownSpeed.Size = new System.Drawing.Size(141, 27); this.checkBoxHull.Name = "checkBoxHull";
this.numericUpDownSpeed.TabIndex = 3; this.checkBoxHull.Size = new System.Drawing.Size(237, 24);
this.numericUpDownSpeed.Value = new decimal(new int[] { this.checkBoxHull.TabIndex = 5;
100, this.checkBoxHull.Text = "Наличие усиленного корпуса";
0, this.checkBoxHull.UseVisualStyleBackColor = true;
0,
0});
// //
// numericUpDownWeight // numericUpDownWeight
// //
@ -221,56 +231,65 @@
0, 0,
0}); 0});
// //
// checkBoxHull // numericUpDownSpeed
// //
this.checkBoxHull.AutoSize = true; this.numericUpDownSpeed.Location = new System.Drawing.Point(118, 34);
this.checkBoxHull.Location = new System.Drawing.Point(6, 127); this.numericUpDownSpeed.Maximum = new decimal(new int[] {
this.checkBoxHull.Name = "checkBoxHull"; 1000,
this.checkBoxHull.Size = new System.Drawing.Size(237, 24); 0,
this.checkBoxHull.TabIndex = 5; 0,
this.checkBoxHull.Text = "Наличие усиленного корпуса"; 0});
this.checkBoxHull.UseVisualStyleBackColor = true; this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(141, 27);
this.numericUpDownSpeed.TabIndex = 3;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
// //
// checkBoxSail // labelWeight
// //
this.checkBoxSail.AutoSize = true; this.labelWeight.AutoSize = true;
this.checkBoxSail.Location = new System.Drawing.Point(6, 168); this.labelWeight.Location = new System.Drawing.Point(25, 79);
this.checkBoxSail.Name = "checkBoxSail"; this.labelWeight.Name = "labelWeight";
this.checkBoxSail.Size = new System.Drawing.Size(169, 24); this.labelWeight.Size = new System.Drawing.Size(36, 20);
this.checkBoxSail.TabIndex = 6; this.labelWeight.TabIndex = 2;
this.checkBoxSail.Text = "Наличие парусника"; this.labelWeight.Text = "Вес:";
this.checkBoxSail.UseVisualStyleBackColor = true;
// //
// labelSimpleObject // labelSpeed
// //
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.labelSpeed.AutoSize = true;
this.labelSimpleObject.Location = new System.Drawing.Point(345, 225); this.labelSpeed.Location = new System.Drawing.Point(25, 36);
this.labelSimpleObject.Name = "labelSimpleObject"; this.labelSpeed.Name = "labelSpeed";
this.labelSimpleObject.Size = new System.Drawing.Size(140, 40); this.labelSpeed.Size = new System.Drawing.Size(76, 20);
this.labelSimpleObject.TabIndex = 7; this.labelSpeed.TabIndex = 1;
this.labelSimpleObject.Text = "Простой"; this.labelSpeed.Text = "Скорость:";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
// //
// labelModifiedObject // panelObject
// //
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panelObject.Controls.Add(this.pictureBoxObject);
this.labelModifiedObject.Location = new System.Drawing.Point(489, 225); this.panelObject.Controls.Add(this.labelAddColor);
this.labelModifiedObject.Name = "labelModifiedObject"; this.panelObject.Controls.Add(this.labelColor);
this.labelModifiedObject.Size = new System.Drawing.Size(140, 40); this.panelObject.Location = new System.Drawing.Point(658, 12);
this.labelModifiedObject.TabIndex = 8; this.panelObject.Name = "panelObject";
this.labelModifiedObject.Text = "Продвинутый"; this.panelObject.Size = new System.Drawing.Size(362, 330);
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.panelObject.TabIndex = 2;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
// //
// panel1 // pictureBoxObject
// //
this.panel1.Controls.Add(this.pictureBoxObject); this.pictureBoxObject.Location = new System.Drawing.Point(3, 61);
this.panel1.Controls.Add(this.labelAddColor); this.pictureBoxObject.Name = "pictureBoxObject";
this.panel1.Controls.Add(this.labelColor); this.pictureBoxObject.Size = new System.Drawing.Size(356, 266);
this.panel1.Location = new System.Drawing.Point(658, 12); this.pictureBoxObject.TabIndex = 11;
this.panel1.Name = "panel1"; this.pictureBoxObject.TabStop = false;
this.panel1.Size = new System.Drawing.Size(362, 330);
this.panel1.TabIndex = 2;
// //
// labelAddColor // labelAddColor
// //
@ -292,22 +311,15 @@
this.labelColor.Text = "Цвет"; this.labelColor.Text = "Цвет";
this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// //
// pictureBoxObject // buttonOk
// //
this.pictureBoxObject.Location = new System.Drawing.Point(3, 61); this.buttonOk.Location = new System.Drawing.Point(694, 348);
this.pictureBoxObject.Name = "pictureBoxObject"; this.buttonOk.Name = "buttonOk";
this.pictureBoxObject.Size = new System.Drawing.Size(356, 266); this.buttonOk.Size = new System.Drawing.Size(140, 40);
this.pictureBoxObject.TabIndex = 11; this.buttonOk.TabIndex = 3;
this.pictureBoxObject.TabStop = false; this.buttonOk.Text = "Добавить";
// this.buttonOk.UseVisualStyleBackColor = true;
// buttonAdd this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
this.buttonAdd.Location = new System.Drawing.Point(694, 348);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(140, 40);
this.buttonAdd.TabIndex = 3;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
// //
// buttonCancel // buttonCancel
// //
@ -324,17 +336,17 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1032, 394); this.ClientSize = new System.Drawing.Size(1032, 394);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonOk);
this.Controls.Add(this.panel1); this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxParameters); this.Controls.Add(this.groupBoxParameters);
this.Name = "FormBoatConfig"; this.Name = "FormBoatConfig";
this.Text = "Создание объекта"; this.Text = "Создание объекта";
this.groupBoxColors.ResumeLayout(false); this.groupBoxColors.ResumeLayout(false);
this.groupBoxParameters.ResumeLayout(false); this.groupBoxParameters.ResumeLayout(false);
this.groupBoxParameters.PerformLayout(); this.groupBoxParameters.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
this.panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -360,11 +372,11 @@
private NumericUpDown numericUpDownSpeed; private NumericUpDown numericUpDownSpeed;
private Label labelWeight; private Label labelWeight;
private Label labelSpeed; private Label labelSpeed;
private Panel panel1; private Panel panelObject;
private PictureBox pictureBoxObject; private PictureBox pictureBoxObject;
private Label labelAddColor; private Label labelAddColor;
private Label labelColor; private Label labelColor;
private Button buttonAdd; private Button buttonOk;
private Button buttonCancel; private Button buttonCancel;
} }
} }

View File

@ -16,17 +16,8 @@ namespace Sailboat
{ {
public partial class FormBoatConfig : Form public partial class FormBoatConfig : Form
{ {
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawingBoat? _boat = null; DrawingBoat? _boat = null;
/// <summary>
/// Событие
/// </summary>
private event BoatDelegate? EventAddBoat; private event BoatDelegate? EventAddBoat;
/// <summary>
/// Конструктор
/// </summary>
public FormBoatConfig() public FormBoatConfig()
{ {
InitializeComponent(); InitializeComponent();
@ -41,7 +32,7 @@ namespace Sailboat
// TODO buttonCancel.Click with lambda // TODO buttonCancel.Click with lambda
} }
private void DrawCar() private void DrawBoat()
{ {
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
@ -49,7 +40,7 @@ namespace Sailboat
_boat?.DrawTransport(gr); _boat?.DrawTransport(gr);
pictureBoxObject.Image = bmp; pictureBoxObject.Image = bmp;
} }
public void AddEvent(BoatDelegate ev) internal void AddEvent(BoatDelegate ev)
{ {
if (EventAddBoat == null) if (EventAddBoat == null)
{ {
@ -70,11 +61,6 @@ namespace Sailboat
(sender as Label)?.DoDragDrop((sender as Label)?.Name, (sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy); DragDropEffects.Move | DragDropEffects.Copy);
} }
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e) private void PanelObject_DragEnter(object sender, DragEventArgs e)
{ {
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
@ -103,7 +89,7 @@ namespace Sailboat
pictureBoxObject.Height); pictureBoxObject.Height);
break; break;
} }
DrawCar(); DrawBoat();
} }
private void ButtonOk_Click(object sender, EventArgs e) private void ButtonOk_Click(object sender, EventArgs e)
{ {