From 8bd90876de8716e8b15505e9c95066ff6cc4b766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D0=B8=D1=80=20=D0=9D=D1=83=D0=B3=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Sun, 6 Nov 2022 18:01:28 +0400 Subject: [PATCH] Event work --- Bus/Bus/BusDelegate.cs | 11 ++++++ Bus/Bus/FormBusConfig.Designer.cs | 45 ++++++++++++------------ Bus/Bus/FormBusConfig.cs | 21 ++++++++++- Bus/Bus/FormMapWithSetDoubleDeckerBus.cs | 40 ++++++++++----------- 4 files changed, 73 insertions(+), 44 deletions(-) create mode 100644 Bus/Bus/BusDelegate.cs diff --git a/Bus/Bus/BusDelegate.cs b/Bus/Bus/BusDelegate.cs new file mode 100644 index 0000000..a833c40 --- /dev/null +++ b/Bus/Bus/BusDelegate.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bus +{ + public delegate void BusDelegate(DrawingBus bus); + +} diff --git a/Bus/Bus/FormBusConfig.Designer.cs b/Bus/Bus/FormBusConfig.Designer.cs index fe01efa..380def1 100644 --- a/Bus/Bus/FormBusConfig.Designer.cs +++ b/Bus/Bus/FormBusConfig.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { this.groupBoxConfig = new System.Windows.Forms.GroupBox(); - this.label2 = new System.Windows.Forms.Label(); + this.labelModifiedObject = new System.Windows.Forms.Label(); this.labelSimpleObject = new System.Windows.Forms.Label(); this.groupBoxColors = new System.Windows.Forms.GroupBox(); this.panelPurple = new System.Windows.Forms.Panel(); @@ -51,7 +51,7 @@ this.panelObject = new System.Windows.Forms.Panel(); this.labelDopColor = new System.Windows.Forms.Label(); this.labelColor = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); + this.buttonOk = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.groupBoxConfig.SuspendLayout(); this.groupBoxColors.SuspendLayout(); @@ -63,7 +63,7 @@ // // groupBoxConfig // - this.groupBoxConfig.Controls.Add(this.label2); + this.groupBoxConfig.Controls.Add(this.labelModifiedObject); this.groupBoxConfig.Controls.Add(this.labelSimpleObject); this.groupBoxConfig.Controls.Add(this.groupBoxColors); this.groupBoxConfig.Controls.Add(this.checkBoxBodyKit); @@ -80,16 +80,16 @@ this.groupBoxConfig.TabStop = false; this.groupBoxConfig.Text = "Параметры"; // - // label2 + // labelModifiedObject // - this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.label2.Location = new System.Drawing.Point(221, 182); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(188, 25); - this.label2.TabIndex = 9; - this.label2.Text = "Продвинутый"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.label2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelModifiedObject.Location = new System.Drawing.Point(221, 182); + this.labelModifiedObject.Name = "labelModifiedObject"; + this.labelModifiedObject.Size = new System.Drawing.Size(188, 25); + this.labelModifiedObject.TabIndex = 9; + this.labelModifiedObject.Text = "Продвинутый"; + this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); // // labelSimpleObject // @@ -300,14 +300,15 @@ this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragDrop); this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // - // button1 + // buttonOk // - this.button1.Location = new System.Drawing.Point(460, 200); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(118, 37); - this.button1.TabIndex = 3; - this.button1.Text = "Добавить"; - this.button1.UseVisualStyleBackColor = true; + this.buttonOk.Location = new System.Drawing.Point(460, 200); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(118, 37); + this.buttonOk.TabIndex = 3; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); // // buttonCancel // @@ -324,7 +325,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(722, 249); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.button1); + this.Controls.Add(this.buttonOk); this.Controls.Add(this.panelObject); this.Controls.Add(this.groupBoxConfig); this.Name = "FormBusConfig"; @@ -360,12 +361,12 @@ private Panel panelWhite; private Panel panelGreen; private Panel panelRed; - private Label label2; + private Label labelModifiedObject; private PictureBox pictureBoxObject; private Panel panelObject; private Label labelDopColor; private Label labelColor; - private Button button1; + private Button buttonOk; private Button buttonCancel; } } \ No newline at end of file diff --git a/Bus/Bus/FormBusConfig.cs b/Bus/Bus/FormBusConfig.cs index d5f16ea..a4a75a5 100644 --- a/Bus/Bus/FormBusConfig.cs +++ b/Bus/Bus/FormBusConfig.cs @@ -14,7 +14,7 @@ namespace Bus { DrawingBus _bus = null; - //private event BusDelegate EventAddBus; + private event BusDelegate EventAddBus; public FormBusConfig() { @@ -44,6 +44,19 @@ namespace Bus pictureBoxObject.Image = bmp; } + public void AddEvent(BusDelegate ev) + { + if (EventAddBus == null) + { + EventAddBus = new BusDelegate(ev); + } + else + { + EventAddBus += ev; + } + + } + private void PanelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) @@ -131,5 +144,11 @@ namespace Bus e.Effect = DragDropEffects.None; } } + + private void buttonOk_Click(object sender, EventArgs e) + { + EventAddBus?.Invoke(_bus); + Close(); + } } } diff --git a/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs b/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs index 0150735..c653939 100644 --- a/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs +++ b/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs @@ -80,34 +80,32 @@ namespace Bus private void ButtonAddBus_Click(object sender, EventArgs e) { - if (_mapBusCollectionGeneric == null) + var formBusConfig = new FormBusConfig(); + // TODO Call method AddEvent from fromBusConfig + formBusConfig.AddEvent(AddBus); + formBusConfig.Show(); + } + + private void AddBus(DrawingBus bus) + { + if (listBoxMaps.SelectedIndex == -1) { return; } - FormBus form = new(); - if (form.ShowDialog() == DialogResult.OK) + DrawingObjectBus boat = new(bus); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0) { - if (form.SelectedBus == null) - { - MessageBox.Show("Сначала создайте объект"); - return; - } - - DrawingObjectBus bus = new(form.SelectedBus); - - if (_mapBusCollectionGeneric + bus != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapBusCollectionGeneric.ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } - private void ButtonRemoveBus_Click(object sender, EventArgs e) + + private void ButtonRemoveBus_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) {