黄学彪
2020-07-09 5428935270159bfc42c2934ed7fb1091554fc9a4
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs
@@ -17,12 +17,14 @@
        private bool m_CanClick = true;
        /// <summary>
        /// 设置能否触点击事件
        /// </summary>
        /// </summary>
        public bool CanClick
        {
            get { return m_CanClick; }
            set
            {
                if (m_CanClick == value) { return; }
                m_CanClick = value;
                //能够点击,则显示没有点击过的状态
                if (m_CanClick == true) { this.SetNotClickStatu(); }
@@ -37,6 +39,15 @@
        {
            set { this.Radius = (uint)Application.GetRealHeight(value); }
        }
        /// <summary>
        /// 声明此变量,旨在子线程也能够去获取一个控件的主键
        /// </summary>
        public string MainKey = string.Empty;
        /// <summary>
        /// 点击的坐标
        /// </summary>
        private System.Drawing.Point downPoint = new System.Drawing.Point();
        /// <summary>
        /// 控件的点击事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
@@ -46,6 +57,27 @@
        /// 控件的按下事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
        /// </summary>
        public Action<Button, MouseEventArgs> ButtonDownClickEvent = null;
        /// <summary>
        /// 控件触发移动的事件(自身拥有算法,当移动多少像素后,触发事件,注意,该事件可能会频繁的触发)
        /// </summary>
        public Action ButtonHappenMoveEvent = null;
        #endregion
        #region ■ 重写彪哥的属性_____________________
        /// <summary>
        /// 重写Text属性
        /// </summary>
        public new string Text
        {
            //先这么弄先吧
            get { return base.Text == null ? string.Empty : base.Text; }
            set
            {
                base.Text = value == null ? string.Empty : value;
            }
        }
        #endregion
@@ -66,13 +98,15 @@
            this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler;
            //按下事件
            this.MouseDownEventHandler += ButtonBase_MouseDownEventHandler;
            //移动事件
            this.MouseMoveEventHandler += ButtonBase_MouseMoveEventHandler;
        }
        /// <summary>
        /// 初始化控件大小(不以平均值进行真实数值计算)
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="real">是否计算真实值</param>
        public void InitSize(int i_Width, int i_Height, bool real = true)
        {
@@ -80,42 +114,60 @@
            {
                i_Width = Application.GetRealWidth(i_Width);
                i_Height = Application.GetRealHeight(i_Height);
            }
            this.Height = i_Height;
            }
            this.Height = i_Height;
            this.Width = i_Width;
        }
        /// <summary>
        /// 初始化控件大小(不以平均值进行真实数值计算)
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Width">宽度</param>
        /// <param name="real">是否计算真实值</param>
        public void InitSize(int i_Width, bool real = false)
        {
            if (real == true)
            {
                i_Width = Application.GetRealWidth(i_Width);
            }
            this.Height = ControlCommonResourse.NormalControlHeight;
            }
            this.Height = ControlCommonResourse.NormalControlHeight;
            this.Width = i_Width;
        }
        /// <summary>
        /// 初始化控件大小(以平均值进行真实数值计算)
        /// 初始化图标控件大小(以平均值进行真实数值计算)
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="real">是否计算真实值</param>
        public void InitAvgSize(int i_Width, int i_Height, bool real = true)
        public void InitIconSize(int i_Width, int i_Height, bool real = true)
        {
            if (real == true)
            {
                i_Width = Application.GetMinRealAverage(i_Width);
                i_Height = Application.GetMinRealAverage(i_Height);
            }
            this.Height = i_Height;
                i_Width = this.GetPictrueRealSize(i_Width);
                i_Height = this.GetPictrueRealSize(i_Height);
            }
            this.Height = i_Height;
            this.Width = i_Width;
        }
        /// <summary>
        /// 初始化图片控件大小
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="real">是否计算真实值</param>
        public void InitPictrueSize(int i_Width, int i_Height, bool real = true)
        {
            if (real == true)
            {
                i_Width = HdlControlLogic.Current.GetPictrueRealSize(i_Width);
                i_Height = HdlControlLogic.Current.GetPictrueRealSize(i_Height);
            }
            this.Height = i_Height;
            this.Width = i_Width;
        }
@@ -135,7 +187,8 @@
                this.MouseUpEventHandler -= ButtonBase_MouseUpEventHandler;
                return;
            }
            if (CanClick == true)
            //2020.05.14追加IsFormAdding:界面还在加载中,不能再点击
            if (CanClick == true && ControlCommonResourse.IsFormAdding == false)
            {
                //Log出力
                this.WriteLog(0);
@@ -166,6 +219,10 @@
        /// <param name="e"></param>
        private void ButtonBase_MouseDownEventHandler(object sender, MouseEventArgs e)
        {
            //记录起当前点击的坐标
            downPoint.X = (int)e.X;
            downPoint.Y = (int)e.Y;
            if (CanClick == false || this.ButtonDownClickEvent == null)
            {
                //不能点击
@@ -183,6 +240,38 @@
                alert.Show();
                //Log出力
                HdlLogLogic.Current.WriteLog(ex);
            }
        }
        #endregion
        #region ■ 移动事件___________________________
        /// <summary>
        /// 移动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonBase_MouseMoveEventHandler(object sender, MouseEventArgs e)
        {
            if (this.ButtonHappenMoveEvent == null)
            {
                this.MouseMoveEventHandler -= ButtonBase_MouseMoveEventHandler;
                return;
            }
            int value = (int)e.X - this.downPoint.X;
            if (value >= 30 || value <= -30)
            {
                //触发移动事件
                this.ButtonHappenMoveEvent();
                return;
            }
            value = (int)e.Y - this.downPoint.Y;
            if (value >= 30 || value <= -30)
            {
                //触发移动事件
                this.ButtonHappenMoveEvent();
                return;
            }
        }
@@ -216,22 +305,10 @@
            ButtonClickEvent = null;
            ButtonDownClickEvent = null;
            base.RemoveFromParent();
        }
        /// <summary>
        /// Y轴重置(真实数值,没有父容器无效)
        /// </summary>
        /// <param name="alignment">上下对齐方式</param>
        /// <param name="Space">上下两部分的间距</param>
        public void ReSetYaxis(UViewAlignment alignment, int Space = 0)
        {
            if (this.Parent == null)
            if (this.Parent != null)
            {
                return;
                base.RemoveFromParent();
            }
            //Y轴重置
            this.Y = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
        }
        /// <summary>
@@ -240,6 +317,7 @@
        /// <returns></returns>
        public int GetRealWidthByText()
        {
            if (string.IsNullOrEmpty(this.Text) == true) { return Application.GetRealWidth(25); }
#if Android
            //需要增加一个误差值
            return this.GetTextWidth() + Application.GetRealWidth(12);
@@ -250,6 +328,16 @@
#endif
        }
        /// <summary>
        /// 计算图片的真实高宽度
        /// </summary>
        /// <param name="i_size"></param>
        /// <returns></returns>
        public int GetPictrueRealSize(int i_size)
        {
            return HdlControlLogic.Current.GetPictrueRealSize(i_size);
        }
        #endregion
        #region ■ Log出力____________________________
@@ -257,7 +345,7 @@
        /// <summary>
        /// 该控件所属的界面名字
        /// </summary>
        private string formName = null;
        public string formName = null;
        /// <summary>
        /// 控件名字
        /// </summary>