Event work
This commit is contained in:
parent
05dcc639bc
commit
01ea98b1c7
13
Boats/Boats/BoatDelegate.cs
Normal file
13
Boats/Boats/BoatDelegate.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Boats
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Делегат для передачи объекта-лодки
|
||||||
|
/// </summary>
|
||||||
|
public delegate void BoatDelegate(DrawingBoat boat);
|
||||||
|
}
|
41
Boats/Boats/FormBoatConfig.Designer.cs
generated
41
Boats/Boats/FormBoatConfig.Designer.cs
generated
@ -46,12 +46,12 @@
|
|||||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||||
this.labelWeight = new System.Windows.Forms.Label();
|
this.labelWeight = new System.Windows.Forms.Label();
|
||||||
this.labelSpeed = new System.Windows.Forms.Label();
|
this.labelSpeed = new System.Windows.Forms.Label();
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
this.buttonOk = new System.Windows.Forms.Button();
|
||||||
this.panelObject = new System.Windows.Forms.Panel();
|
this.panelObject = new System.Windows.Forms.Panel();
|
||||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||||
this.labelDopColor = new System.Windows.Forms.Label();
|
this.labelDopColor = new System.Windows.Forms.Label();
|
||||||
this.labelBaseColor = new System.Windows.Forms.Label();
|
this.labelBaseColor = new System.Windows.Forms.Label();
|
||||||
this.button2 = new System.Windows.Forms.Button();
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
this.groupBoxConfig.SuspendLayout();
|
this.groupBoxConfig.SuspendLayout();
|
||||||
this.groupBoxColors.SuspendLayout();
|
this.groupBoxColors.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||||
@ -251,14 +251,15 @@
|
|||||||
this.labelSpeed.TabIndex = 0;
|
this.labelSpeed.TabIndex = 0;
|
||||||
this.labelSpeed.Text = "Скорость:";
|
this.labelSpeed.Text = "Скорость:";
|
||||||
//
|
//
|
||||||
// button1
|
// buttonOk
|
||||||
//
|
//
|
||||||
this.button1.Location = new System.Drawing.Point(595, 216);
|
this.buttonOk.Location = new System.Drawing.Point(595, 216);
|
||||||
this.button1.Name = "button1";
|
this.buttonOk.Name = "buttonOk";
|
||||||
this.button1.Size = new System.Drawing.Size(119, 29);
|
this.buttonOk.Size = new System.Drawing.Size(119, 29);
|
||||||
this.button1.TabIndex = 7;
|
this.buttonOk.TabIndex = 7;
|
||||||
this.button1.Text = "Добавить";
|
this.buttonOk.Text = "Добавить";
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
this.buttonOk.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||||
//
|
//
|
||||||
// panelObject
|
// panelObject
|
||||||
//
|
//
|
||||||
@ -307,24 +308,24 @@
|
|||||||
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||||
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
|
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
|
||||||
//
|
//
|
||||||
// button2
|
// buttonCancel
|
||||||
//
|
//
|
||||||
this.button2.Location = new System.Drawing.Point(736, 217);
|
this.buttonCancel.Location = new System.Drawing.Point(736, 217);
|
||||||
this.button2.Name = "button2";
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
this.button2.Size = new System.Drawing.Size(119, 29);
|
this.buttonCancel.Size = new System.Drawing.Size(119, 29);
|
||||||
this.button2.TabIndex = 8;
|
this.buttonCancel.TabIndex = 8;
|
||||||
this.button2.Text = "Отмена";
|
this.buttonCancel.Text = "Отмена";
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// FormBoatConfig
|
// FormBoatConfig
|
||||||
//
|
//
|
||||||
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(888, 258);
|
this.ClientSize = new System.Drawing.Size(888, 258);
|
||||||
this.Controls.Add(this.button2);
|
this.Controls.Add(this.buttonCancel);
|
||||||
this.Controls.Add(this.panelObject);
|
this.Controls.Add(this.panelObject);
|
||||||
this.Controls.Add(this.groupBoxConfig);
|
this.Controls.Add(this.groupBoxConfig);
|
||||||
this.Controls.Add(this.button1);
|
this.Controls.Add(this.buttonOk);
|
||||||
this.Name = "FormBoatConfig";
|
this.Name = "FormBoatConfig";
|
||||||
this.Text = "Создание объекта";
|
this.Text = "Создание объекта";
|
||||||
this.groupBoxConfig.ResumeLayout(false);
|
this.groupBoxConfig.ResumeLayout(false);
|
||||||
@ -358,11 +359,11 @@
|
|||||||
private NumericUpDown numericUpDownSpeed;
|
private NumericUpDown numericUpDownSpeed;
|
||||||
private Label labelWeight;
|
private Label labelWeight;
|
||||||
private Label labelSpeed;
|
private Label labelSpeed;
|
||||||
private Button button1;
|
private Button buttonOk;
|
||||||
private Panel panelObject;
|
private Panel panelObject;
|
||||||
private PictureBox pictureBoxObject;
|
private PictureBox pictureBoxObject;
|
||||||
private Label labelBaseColor;
|
private Label labelBaseColor;
|
||||||
private Label labelDopColor;
|
private Label labelDopColor;
|
||||||
private Button button2;
|
private Button buttonCancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,6 +21,10 @@ namespace Boats
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
DrawingBoat _boat = null;
|
DrawingBoat _boat = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Событие
|
||||||
|
/// </summary>
|
||||||
|
private event BoatDelegate EventAddBoat;
|
||||||
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormBoatConfig()
|
public FormBoatConfig()
|
||||||
@ -34,6 +38,8 @@ namespace Boats
|
|||||||
panelGray.MouseDown += PanelColor_MouseDown;
|
panelGray.MouseDown += PanelColor_MouseDown;
|
||||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||||
panelNavy.MouseDown += PanelColor_MouseDown;
|
panelNavy.MouseDown += PanelColor_MouseDown;
|
||||||
|
|
||||||
|
buttonCancel.Click += (sender, e) => Close();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отрисовка лодки
|
/// Отрисовка лодки
|
||||||
@ -47,6 +53,21 @@ namespace Boats
|
|||||||
pictureBoxObject.Image = bmp;
|
pictureBoxObject.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Добавление события
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
public void AddEvent(BoatDelegate e)
|
||||||
|
{
|
||||||
|
if (EventAddBoat == null)
|
||||||
|
{
|
||||||
|
EventAddBoat = new BoatDelegate(e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EventAddBoat += e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// Применяем соответствующий объект
|
/// Применяем соответствующий объект
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
@ -161,5 +182,15 @@ namespace Boats
|
|||||||
(_boat.Boat as EntityCatamaran).DopColor = labelDopColor.BackColor;
|
(_boat.Boat as EntityCatamaran).DopColor = labelDopColor.BackColor;
|
||||||
DrawBoat();
|
DrawBoat();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление лодки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonOk_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
EventAddBoat?.Invoke(_boat);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,24 +99,9 @@ namespace Boats
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxMaps.SelectedIndex == -1)
|
var formBoatConfig = new FormBoatConfig();
|
||||||
{
|
formBoatConfig.AddEvent(new BoatDelegate(AddBoatListener));
|
||||||
return;
|
formBoatConfig.Show();
|
||||||
}
|
|
||||||
FormBoat form = new();
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
DrawingObjectBoat boat = new(form.SelectedBoat);
|
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat != -1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Объект добавлен");
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта
|
/// Удаление объекта
|
||||||
@ -255,5 +240,26 @@ namespace Boats
|
|||||||
{
|
{
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Listener для добавления новой лодки из формы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawingBoat"></param>
|
||||||
|
private void AddBoatListener(DrawingBoat drawingBoat)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawingObjectBoat boat = new(drawingBoat);
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace Boats
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormBoatConfig());
|
Application.Run(new FormMapWithSetBoats());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user