黄学彪
2019-12-09 163777d8a2cb7cfa469f54a7042528870ebc10a3
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs
@@ -30,11 +30,22 @@
                else { this.SetClickStatu(); }
            }
        }
        /// <summary>
        /// 圆角度
        /// </summary>
        public int RadiusEx
        {
            set { this.Radius = (uint)Application.GetRealHeight(value); }
        }
        /// <summary>
        /// 控件的点击事件(此事件被认可为执行按钮按下事件,受CanClick属性控制)
        /// 控件的点击事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
        /// </summary>
        public Action<Button, MouseEventArgs> ButtonClickEvent = null;
        /// <summary>
        /// 控件的按下事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
        /// </summary>
        public Action<Button, MouseEventArgs> ButtonDownClickEvent = null;
        #endregion
@@ -53,6 +64,8 @@
            //点击事件
            this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler;
            //按下事件
            this.MouseDownEventHandler += ButtonBase_MouseDownEventHandler;
        }
        /// <summary>
@@ -125,20 +138,51 @@
            if (CanClick == true)
            {
                //Log出力
                this.WriteLog();
                this.WriteLog(0);
                try
                {
                    this.ButtonClickEvent?.Invoke(this, e);
                    this.ButtonClickEvent(this, e);
                }
                catch (Exception ex)
                {
                    //出现未知错误,数据丢失
                    var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
                    //出现未知错误
                    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_MouseDownEventHandler(object sender, MouseEventArgs e)
        {
            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);
            }
        }
@@ -165,21 +209,13 @@
        #region ■ 一般方法___________________________
        /// <summary>
        /// 重置单击事件(此操作委托会变null)
        /// </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;
            base.RemoveFromParent();
        }
@@ -230,19 +266,7 @@
                //byteLength += Encoding.GetEncoding("gb2312").GetBytes(i_text[i].ToString()).Length;
            }
            int realWidth = byteLength * (int)textSize;
            return Application.GetRealWidth(realWidth);
        }
        /// <summary>
        /// 添加底部阴影特效(确保拥有父控件后才调用)
        /// </summary>
        public void AddBottomShadow()
        {
            var btnShadow = new PicViewControl(this.Width, Application.GetMinRealAverage(45), false);
            btnShadow.X = this.X;
            btnShadow.Y = this.Bottom - 1;
            btnShadow.UnSelectedImagePath = "Item/BottomShadow.png";
            this.Parent.AddChidren(btnShadow);
            return Application.GetRealWidth(realWidth + 20);
        }
        #endregion
@@ -261,7 +285,7 @@
        /// <summary>
        /// Log出力
        /// </summary>
        private void WriteLog()
        private void WriteLog(int div)
        {
            if (formName == null)
            {
@@ -292,7 +316,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