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.labelWeight = 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.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.labelDopColor = 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.groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
@ -251,14 +251,15 @@
|
||||
this.labelSpeed.TabIndex = 0;
|
||||
this.labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// button1
|
||||
// buttonOk
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(595, 216);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(119, 29);
|
||||
this.button1.TabIndex = 7;
|
||||
this.button1.Text = "Добавить";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Location = new System.Drawing.Point(595, 216);
|
||||
this.buttonOk.Name = "buttonOk";
|
||||
this.buttonOk.Size = new System.Drawing.Size(119, 29);
|
||||
this.buttonOk.TabIndex = 7;
|
||||
this.buttonOk.Text = "Добавить";
|
||||
this.buttonOk.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
@ -307,24 +308,24 @@
|
||||
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
|
||||
//
|
||||
// button2
|
||||
// buttonCancel
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(736, 217);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(119, 29);
|
||||
this.button2.TabIndex = 8;
|
||||
this.button2.Text = "Отмена";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Location = new System.Drawing.Point(736, 217);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(119, 29);
|
||||
this.buttonCancel.TabIndex = 8;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormBoatConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
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.groupBoxConfig);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.buttonOk);
|
||||
this.Name = "FormBoatConfig";
|
||||
this.Text = "Создание объекта";
|
||||
this.groupBoxConfig.ResumeLayout(false);
|
||||
@ -358,11 +359,11 @@
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelWeight;
|
||||
private Label labelSpeed;
|
||||
private Button button1;
|
||||
private Button buttonOk;
|
||||
private Panel panelObject;
|
||||
private PictureBox pictureBoxObject;
|
||||
private Label labelBaseColor;
|
||||
private Label labelDopColor;
|
||||
private Button button2;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
@ -21,6 +21,10 @@ namespace Boats
|
||||
/// </summary>
|
||||
DrawingBoat _boat = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
private event BoatDelegate EventAddBoat;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormBoatConfig()
|
||||
@ -34,6 +38,8 @@ namespace Boats
|
||||
panelGray.MouseDown += PanelColor_MouseDown;
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelNavy.MouseDown += PanelColor_MouseDown;
|
||||
|
||||
buttonCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовка лодки
|
||||
@ -47,6 +53,21 @@ namespace Boats
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
public void AddEvent(BoatDelegate e)
|
||||
{
|
||||
if (EventAddBoat == null)
|
||||
{
|
||||
EventAddBoat = new BoatDelegate(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddBoat += e;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Применяем соответствующий объект
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -161,5 +182,15 @@ namespace Boats
|
||||
(_boat.Boat as EntityCatamaran).DopColor = labelDopColor.BackColor;
|
||||
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>
|
||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
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("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
var formBoatConfig = new FormBoatConfig();
|
||||
formBoatConfig.AddEvent(new BoatDelegate(AddBoatListener));
|
||||
formBoatConfig.Show();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
@ -255,5 +240,26 @@ namespace Boats
|
||||
{
|
||||
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,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormBoatConfig());
|
||||
Application.Run(new FormMapWithSetBoats());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user