From 7132f8f3225e3a8cd4c187bfebf87e7e1148fa10 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Thu, 3 Nov 2022 14:01:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8(Drag=20dro?= =?UTF-8?q?p)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/FormShipConfig.Designer.cs | 4 ++-- Liner/Liner/FormShipConfig.cs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Liner/Liner/FormShipConfig.Designer.cs b/Liner/Liner/FormShipConfig.Designer.cs index 5c597eb..fff8435 100644 --- a/Liner/Liner/FormShipConfig.Designer.cs +++ b/Liner/Liner/FormShipConfig.Designer.cs @@ -287,7 +287,7 @@ this.LabelDopColor.Text = "Доп. цвет"; this.LabelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.LabelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop); - this.LabelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter); + this.LabelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter); // // LabelBaseColor // @@ -300,7 +300,7 @@ this.LabelBaseColor.Text = "Цвет"; this.LabelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 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.LabelColor_DragEnter); // // pictureBoxObject // diff --git a/Liner/Liner/FormShipConfig.cs b/Liner/Liner/FormShipConfig.cs index 5814faa..169e877 100644 --- a/Liner/Liner/FormShipConfig.cs +++ b/Liner/Liner/FormShipConfig.cs @@ -80,9 +80,9 @@ namespace Liner } DrawShip(); } - private void setDragEffect(DragEventArgs e, Type needTypeData, bool condition) + private void LabelColor_DragEnter(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(needTypeData) && condition) + if (e.Data.GetDataPresent(typeof(Color))) { e.Effect = DragDropEffects.Copy; } @@ -91,16 +91,18 @@ namespace Liner e.Effect = DragDropEffects.None; } } - private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _ship != null); - private void LabelDopColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _ship != null && _ship is DrawningLiner); private void LabelBaseColor_DragDrop(object sender, DragEventArgs e) { + if (_ship == null) + { + return; + } _ship.SetColor((Color)e.Data.GetData(typeof(Color))); DrawShip(); } private void LabelDopColor_DragDrop(object sender, DragEventArgs e) { - if (_ship is not DrawningLiner liner) + if (_ship == null || _ship is not DrawningLiner liner) { return; }