From b3e96fce4cc01113128ddf8e0a18fc19594a9e56 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 05 十二月 2019 18:38:30 +0800
Subject: [PATCH] 一个新的版本

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs |  130 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 111 insertions(+), 19 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs
index 36c8452..42798c2 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs
@@ -32,17 +32,22 @@
         }
 
         /// <summary>
-        /// 鎺т欢鐨勭偣鍑讳簨浠�(姝や簨浠惰璁ゅ彲涓烘墽琛屾寜閽寜涓嬩簨浠讹紝鍙桟anClick灞炴�ф帶鍒�)
+        /// 鏄惁鏄暱鎸夌姸鎬�
+        /// </summary>
+        private bool isLongClick = false;
+
+        /// <summary>
+        /// 鎺т欢鐨勭偣鍑讳簨浠�(鑷畾涔夊皝瑁呬簨浠�,姝や簨浠惰璁ゅ彲涓烘墽琛屾寜閽寜涓嬩簨浠�,鍙桟anClick灞炴�ф帶鍒�)
         /// </summary>
         public Action<Button, MouseEventArgs> ButtonClickEvent = null;
         /// <summary>
-        /// 搴曢儴闃村奖鎺т欢1
+        /// (鈽呭綋鍓嶄笉瑕佷娇鐢ㄢ槄)鎺т欢鐨勯暱鎸変簨浠�,褰撲簨浠朵负null鏃�,浠h〃闀挎寜缁撴潫(鑷畾涔夊皝瑁呬簨浠�,姝や簨浠惰璁ゅ彲涓烘墽琛屾寜閽暱鎸変簨浠�,鍙桟anClick灞炴�ф帶鍒�)
         /// </summary>
-        private Button btnBottomShadowView1 = null;
+        public Action<Button, MouseEventArgs> ButtonLongClickEvent = null;
         /// <summary>
-        /// 搴曢儴闃村奖鎺т欢2
+        /// 鎺т欢鐨勬寜涓嬩簨浠�(鑷畾涔夊皝瑁呬簨浠�,姝や簨浠惰璁ゅ彲涓烘墽琛屾寜閽寜涓嬩簨浠�,鍙桟anClick灞炴�ф帶鍒�)
         /// </summary>
-        private Button btnBottomShadowView2 = null;
+        public Action<Button, MouseEventArgs> ButtonDownClickEvent = null;
 
         #endregion
 
@@ -61,6 +66,10 @@
 
             //鐐瑰嚮浜嬩欢
             this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler;
+            //鎸変笅浜嬩欢
+            this.MouseDownEventHandler += ButtonBase_MouseDownEventHandler;
+            //闀挎寜浜嬩欢
+            this.MouseLongEventHandler += ButtonBase_MouseLongEventHandler;
         }
 
         /// <summary>
@@ -133,11 +142,94 @@
             if (CanClick == true)
             {
                 //Log鍑哄姏
-                this.WriteLog();
+                this.WriteLog(0);
 
                 try
                 {
-                    this.ButtonClickEvent?.Invoke(this, e);
+                    if (this.isLongClick == false)
+                    {
+                        this.ButtonClickEvent(this, e);
+                    }
+                    else if (ButtonLongClickEvent != null)
+                    {
+                        //闀挎寜缁撴潫
+                        this.ButtonLongClickEvent(this, null);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    //鍑虹幇鏈煡閿欒
+                    var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
+                    alert.Show();
+                    //Log鍑哄姏
+                    HdlLogLogic.Current.WriteLog(ex);
+                }
+            }
+            //鐘舵�佽繕鍘�
+            this.isLongClick = false;
+        }
+
+        #endregion
+
+        #region 鈻� 鎸変笅浜嬩欢___________________________
+
+        /// <summary>
+        /// 鎸変笅浜嬩欢
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ButtonBase_MouseDownEventHandler(object sender, MouseEventArgs e)
+        {
+            //杩樺師鐘舵��
+            this.isLongClick = false;
+
+            if (CanClick == false || this.ButtonDownClickEvent == null)
+            {
+                //涓嶈兘鐐瑰嚮
+                return;
+            }
+
+            try
+            {
+                this.ButtonDownClickEvent(this, e);
+            }
+            catch (Exception ex)
+            {
+                //鍑虹幇鏈煡閿欒
+                var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
+                alert.Show();
+                //Log鍑哄姏
+                HdlLogLogic.Current.WriteLog(ex);
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 闀挎寜浜嬩欢___________________________
+
+        /// <summary>
+        /// 闀挎寜浜嬩欢
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ButtonBase_MouseLongEventHandler(object sender, MouseEventArgs e)
+        {
+            //闀挎寜鐘舵��
+            this.isLongClick = true;
+
+            if (ButtonLongClickEvent == null)
+            {
+                this.MouseLongEventHandler -= ButtonBase_MouseLongEventHandler;
+                return;
+            }
+            if (CanClick == true)
+            {
+                //Log鍑哄姏
+                this.WriteLog(1);
+
+                try
+                {
+                    this.ButtonLongClickEvent(this, e);
                 }
                 catch (Exception ex)
                 {
@@ -173,21 +265,14 @@
         #region 鈻� 涓�鑸柟娉昣__________________________
 
         /// <summary>
-        /// 閲嶇疆鍗曞嚮浜嬩欢(姝ゆ搷浣滃鎵樹細鍙榥ull)
-        /// </summary>
-        public void ResetClickEvent()
-        {
-            ButtonClickEvent = null;
-            this.MouseUpEventHandler -= this.ButtonBase_MouseUpEventHandler;
-            this.MouseUpEventHandler += this.ButtonBase_MouseUpEventHandler;
-        }
-
-        /// <summary>
         /// 鎺т欢鎽ф瘉
         /// </summary>
         public override void RemoveFromParent()
         {
             ButtonClickEvent = null;
+            ButtonDownClickEvent = null;
+            ButtonLongClickEvent = null;
+
             base.RemoveFromParent();
         }
 
@@ -257,7 +342,7 @@
         /// <summary>
         /// Log鍑哄姏
         /// </summary>
-        private void WriteLog()
+        private void WriteLog(int div)
         {
             if (formName == null)
             {
@@ -288,7 +373,14 @@
                     controlName = this.UnSelectedImagePath;
                 }
             }
-            HdlLogLogic.Current.WriteLog(1, formName + "鐨刐" + controlName + "]鎸夐敭琚偣鍑�");
+            if (div == 0)
+            {
+                HdlLogLogic.Current.WriteLog(1, formName + "鐨刐" + controlName + "]鎸夐敭琚偣鍑�");
+            }
+            else
+            {
+                HdlLogLogic.Current.WriteLog(1, formName + "鐨刐" + controlName + "]鎸夐敭琚暱鎸�");
+            }
         }
 
         #endregion

--
Gitblit v1.8.0