gxc
2020-01-02 00ab3ddb140ba8bb88b5cf572b004a85e1da85e9
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs
@@ -30,19 +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>
        /// 底部阴影控件1
        /// 控件的按下事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
        /// </summary>
        private Button btnBottomShadowView1 = null;
        /// <summary>
        /// 底部阴影控件2
        /// </summary>
        private Button btnBottomShadowView2 = null;
        public Action<Button, MouseEventArgs> ButtonDownClickEvent = null;
        #endregion
@@ -61,6 +64,8 @@
            //点击事件
            this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler;
            //按下事件
            this.MouseDownEventHandler += ButtonBase_MouseDownEventHandler;
        }
        /// <summary>
@@ -133,11 +138,11 @@
            if (CanClick == true)
            {
                //Log出力
                this.WriteLog();
                this.WriteLog(0);
                try
                {
                    this.ButtonClickEvent?.Invoke(this, e);
                    this.ButtonClickEvent(this, e);
                }
                catch (Exception ex)
                {
@@ -147,6 +152,37 @@
                    //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);
            }
        }
@@ -173,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();
        }
@@ -207,38 +235,19 @@
        }
        /// <summary>
        /// 根据文本,计算它实际的宽度(返回的是真实值)
        /// 根据文本,计算它实际的宽度
        /// </summary>
        /// <param name="textSize">字体大小,省略时使用当前控件的字体大小</param>
        /// <param name="i_text">需要计算的文本信息,省略时使用当前控件的文本</param>
        /// <returns></returns>
        public int GetRealWidthByText(float textSize, string i_text = null)
        public int GetRealWidthByText()
        {
            if (i_text == null)
            {
                i_text = this.Text;
            }
            if (textSize == -1)
            {
                textSize = this.TextSize;
            }
            int byteLength = 0;
            for (int i = 0; i < i_text.Length; i++)
            {
                byteLength += Encoding.UTF8.GetBytes(i_text[i].ToString()).Length;
                //int length = Encoding.UTF8.GetBytes(i_text[i].ToString()).Length;
                //if (length == 1)
                //{
                //    //英文
                //    byteLength += length;
                //    continue;
                //}
                ////中文(暂时用中文对应)
                //byteLength += Encoding.GetEncoding("gb2312").GetBytes(i_text[i].ToString()).Length;
            }
            int realWidth = byteLength * (int)textSize;
            return Application.GetRealWidth(realWidth + 20);
#if Android
            //需要增加一个误差值
            return this.GetTextWidth() + Application.GetRealWidth(12);
#endif
#if iOS
            //需要增加一个误差值
            return this.GetTextWidth() + Application.GetRealWidth(25);
#endif
        }
        #endregion
@@ -257,7 +266,7 @@
        /// <summary>
        /// Log出力
        /// </summary>
        private void WriteLog()
        private void WriteLog(int div)
        {
            if (formName == null)
            {
@@ -288,7 +297,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