HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-12-14 e90209beae6a4e822cecb18e6889f8bda23f630e
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Common/ClickButtonCommon.cs
old mode 100755 new mode 100644
@@ -1,114 +1,113 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 点击按钮类的共通
    /// </summary>
    public class ClickButtonCommon : ButtonBase
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 是否启用点亮功能(默认启用)
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 点击按钮类的共通
    /// </summary>
    public class ClickButtonCommon : ButtonBase
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 是否启用点亮功能(默认启用)
        /// </summary>
        public bool UseClickStatu = true;
        /// <summary>
        /// 原来的背景色(迫不得己,这个东西需要开放出去,设置一次之后将不会再设置)
        public bool UseClickStatu = true;
        /// <summary>
        /// 原来的背景色(迫不得己,这个东西需要开放出去,设置一次之后将不会再设置)
        /// </summary>
        public uint oldBackgroundColor = 0;
        /// <summary>
        /// 点击状态的背景色(迫不得己,这个东西需要开放出去,默认使用底层设置的)
        /// </summary>
        public uint clickStatuColor = UserCenterColor.Current.ButtonClickStatuColor;
        /// <summary>
        /// 是否处于选择状态
        /// </summary>
        private bool isSelcetStatu = false;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,黑色背景,文字居中)
        /// </summary>
        public ClickButtonCommon()
        {
        public uint oldBackgroundColor = 0;
        /// <summary>
        /// 点击状态的背景色(迫不得己,这个东西需要开放出去,默认使用底层设置的)
        /// </summary>
        public uint clickStatuColor = UserCenterColor.Current.ButtonClickStatuColor;
        /// <summary>
        /// 是否处于选择状态
        /// </summary>
        private bool isSelcetStatu = false;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,黑色背景,文字居中)
        /// </summary>
        public ClickButtonCommon()
        {
            this.TextColor = UserCenterColor.Current.White;
            this.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
            this.TextAlignment = TextAlignment.Center;
            this.MouseDownEventHandler += this.Button_MouseDownEvent;
        }
        #endregion
        #region ■ 控件点亮特效_______________________
        /// <summary>
        /// 单击按下事件
        /// </summary>
        /// <param name="sender"></param>
            this.TextAlignment = TextAlignment.Center;
            this.ButtonDownClickEvent += this.Button_MouseDownEvent;
        }
        #endregion
        #region ■ 控件点亮特效_______________________
        /// <summary>
        /// 单击按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_MouseDownEvent(object sender, MouseEventArgs e)
        {
            if (this.UseClickStatu == false)
            {
                //永久移除
                this.MouseDownEventHandler -= this.Button_MouseDownEvent;
                return;
            }
            if (base.CanClick == false || isSelcetStatu == true)
            {
                //控件不能点击,或者当前处于选择状态,则不能触发
                return;
            }
            if (this.oldBackgroundColor == 0)
            {
                this.oldBackgroundColor = this.BackgroundColor;
            }
            //设置点击后的状态
            this.SetClickStatu();
            new System.Threading.Thread(() =>
            {
                System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
                Application.RunOnMainThread(() =>
                {
                    if (base.CanClick == false || isSelcetStatu == false)
                    {
                        //控件不能点击,或者当前处于非选择状态,则不能触发
                        return;
                    }
                    //设置非点击后的状态
                    this.SetNotClickStatu();
                });
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 设置点击后的状态
        /// </summary>
        public override void SetClickStatu()
        {
            this.isSelcetStatu = true;
            this.BackgroundColor = clickStatuColor;
        }
        /// <summary>
        /// 设置非点击后的状态
        /// </summary>
        public override void SetNotClickStatu()
        {
            this.isSelcetStatu = false;
            //设置不选择状态
            this.BackgroundColor = oldBackgroundColor;
        }
        #endregion
    }
}
        private void Button_MouseDownEvent(object sender, MouseEventArgs e)
        {
            if (this.UseClickStatu == false)
            {
                //永久移除
                this.ButtonDownClickEvent -= Button_MouseDownEvent;
                return;
            }
            if (base.CanClick == false || isSelcetStatu == true)
            {
                //控件不能点击,或者当前处于选择状态,则不能触发
                return;
            }
            if (this.oldBackgroundColor == 0)
            {
                this.oldBackgroundColor = this.BackgroundColor;
            }
            //设置点击后的状态
            this.SetClickStatu();
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    if (base.CanClick == false || isSelcetStatu == false)
                    {
                        //控件不能点击,或者当前处于非选择状态,则不能触发
                        return;
                    }
                    //设置非点击后的状态
                    this.SetNotClickStatu();
                });
            });
        }
        /// <summary>
        /// 设置点击后的状态
        /// </summary>
        public override void SetClickStatu()
        {
            this.isSelcetStatu = true;
            this.BackgroundColor = clickStatuColor;
        }
        /// <summary>
        /// 设置非点击后的状态
        /// </summary>
        public override void SetNotClickStatu()
        {
            this.isSelcetStatu = false;
            //设置不选择状态
            this.BackgroundColor = oldBackgroundColor;
        }
        #endregion
    }
}