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

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)
{
var formBoatConfig = new FormBoatConfig();
formBoatConfig.AddEvent(AddBoat);
formBoatConfig.Show();
}
private void AddBoat(DrawingBoat drawingBoat)
{
if (listBoxStorages.SelectedIndex == -1)
{

View File

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

View File

@ -16,17 +16,8 @@ namespace Sailboat
{
public partial class FormBoatConfig : Form
{
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawingBoat? _boat = null;
/// <summary>
/// Событие
/// </summary>
private event BoatDelegate? EventAddBoat;
/// <summary>
/// Конструктор
/// </summary>
public FormBoatConfig()
{
InitializeComponent();
@ -41,7 +32,7 @@ namespace Sailboat
// TODO buttonCancel.Click with lambda
}
private void DrawCar()
private void DrawBoat()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
@ -49,7 +40,7 @@ namespace Sailboat
_boat?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(BoatDelegate ev)
internal void AddEvent(BoatDelegate ev)
{
if (EventAddBoat == null)
{
@ -70,11 +61,6 @@ namespace Sailboat
(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)
@ -103,7 +89,7 @@ namespace Sailboat
pictureBoxObject.Height);
break;
}
DrawCar();
DrawBoat();
}
private void ButtonOk_Click(object sender, EventArgs e)
{