using System; namespace Shared.Phone.UserCenter { /// /// Button的共通,共有的方法写在里面, /// 初始值:标准字体和颜色,文字向左靠齐 /// public class ButtonCommon : Button { /// /// 单击弹起事件 /// /// /// public delegate void _MouseUpEvent(object sender, MouseEventArgs e); /// /// 单击弹起事件(这事件封装有可单击的时间间隔的功能:5秒) /// public _MouseUpEvent MouseUpEvent; /// /// 能否触发单击弹起事件 /// public bool isCanClickUp = true; /// /// 显示可执行单击弹起的倒计时 /// public bool IsShowMouseUpTime = false; /// /// 弹起间隔2秒(设置为0时,无间隔) /// public int MouseUpTime = 2; /// /// 向上的偏差值 /// public int DeviationValue = Application.GetRealHeight(10); /// /// 初始化(初始值:标准字体颜色,文字向左靠齐) /// public ButtonCommon() { this.TextColor = UserCenterColor.Current.TextColor; this.TextAlignment = TextAlignment.CenterLeft; //测试,全体字体为14号字 this.TextSize = 14; this.MouseUpEventHandler += this.Button_MouseUpEvent; } /// /// 初始化控件大小(不以平均值进行真实数值计算) /// /// 宽度 /// 高度 /// 是否计算真实值 public void InitSize(int i_Width, int i_Height, bool real = true) { if (real == true) { i_Width = Application.GetRealWidth(i_Width); i_Height = Application.GetRealHeight(i_Height); } this.Height = i_Height; this.Width = i_Width; } /// /// 初始化控件大小(不以平均值进行真实数值计算) /// /// 宽度 /// 是否计算真实值 public void InitSize(int i_Width, bool real = false) { if (real == true) { i_Width = Application.GetRealWidth(i_Width); } this.Height = ControlCommonResourse.NormalControlHeight; this.Width = i_Width; } /// /// 初始化控件大小 /// public void InitSize() { this.Height = ControlCommonResourse.NormalControlHeight; this.Width = Application.CurrentWidth - ControlCommonResourse.XXLeft; } /// /// 初始化控件大小(以平均值进行真实数值计算) /// /// 宽度 /// 高度 /// 是否计算真实值 public void InitAvgSize(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; this.Width = i_Width; } /// /// Y轴重置(真实数值,没有父容器无效) /// /// 上下对齐方式 /// 上下两部分的间距 public void ReSetYaxis(UViewAlignment alignment, int Space = 0) { if (this.Parent == null) { return; } //Y轴重置 int YY = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space); if (alignment == UViewAlignment.Top) { YY = YY + this.DeviationValue; } else if (alignment == UViewAlignment.Bottom) { YY = YY - this.DeviationValue; } this.Y = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space); } /// /// 单击弹起事件 /// /// /// private void Button_MouseUpEvent(object sender, MouseEventArgs e) { if (this.MouseUpEvent == null) { //永久移除事件 this.MouseUpEventHandler -= this.Button_MouseUpEvent; return; } if (this.isCanClickUp == false) { return; } if (this.MouseUpTime > 0) { this.isCanClickUp = false; string text = this.Text; new System.Threading.Thread(() => { //不能够连续狂点 int myTime = this.MouseUpTime; while (myTime >= 0) { if (this.IsShowMouseUpTime == true) { Application.RunOnMainThread(() => { this.Text = text + "(" + myTime + ")"; }); } System.Threading.Thread.Sleep(1000); myTime--; } this.isCanClickUp = true; if (this.IsShowMouseUpTime == true) { Application.RunOnMainThread(() => { this.Text = text; }); } }) { IsBackground = true }.Start(); } //执行自定义的事件 this.MouseUpEvent(sender, e); } } /// /// Icon类的共通 /// public class ButtonIconCommon : ButtonCommon { /// /// 是否启用点亮功能(默认不启用) /// public bool UseClickStatu = false; /// /// Icon类的共通 /// public ButtonIconCommon() { //这个事件是搞点亮特效的 this.MouseDownEventHandler += this.Button_MouseDownEvent; } /// /// 单击按下事件 /// /// /// private void Button_MouseDownEvent(object sender, MouseEventArgs e) { if (this.UseClickStatu == false) { //永久移除 this.MouseDownEventHandler -= this.Button_MouseDownEvent; return; } if (string.IsNullOrEmpty(this.SelectedImagePath) == false) { //设置选择的状态 this.SetSelectStatu(); if (string.IsNullOrEmpty(this.UnSelectedImagePath) == false) { new System.Threading.Thread(() => { System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime); Application.RunOnMainThread(() => { //设置不选择状态 this.SetNotSelectStatu(); }); }) { IsBackground = true }.Start(); } } else if (string.IsNullOrEmpty(this.Text) == false) { uint oldColor = this.TextColor; //设置选择状态 this.TextColor = UserCenterColor.Current.SelectTextColor; new System.Threading.Thread(() => { System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime); Application.RunOnMainThread(() => { //设置不选择状态 this.TextColor = oldColor; }); }) { IsBackground = true }.Start(); } } /// /// 设置选择的状态 /// public void SetSelectStatu() { this.IsSelected = true; } /// /// 设置非选择的状态 /// public void SetNotSelectStatu() { Application.RunOnMainThread(() => { //设置不选择状态 this.IsSelected = false; }); } } /// /// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,蓝色背景,文字居中) /// public class ClickButtonCommon : ButtonCommon { /// /// 是否启用点亮功能(默认不启用) /// public bool UseClickStatu = false; /// /// 原来的背景色 /// private uint oldBackgroundColor = 0; /// /// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,蓝色背景,文字居中) /// public ClickButtonCommon() { this.TextColor = UserCenterColor.Current.White; this.BackgroundColor = UserCenterColor.Current.ClickButtonColor; this.TextAlignment = TextAlignment.Center; this.MouseDownEventHandler += this.Button_MouseDownEvent; } /// /// 单击按下事件 /// /// /// private void Button_MouseDownEvent(object sender, MouseEventArgs e) { if (this.UseClickStatu == false) { //永久移除 this.MouseDownEventHandler -= this.Button_MouseDownEvent; return; } //设置点击后的状态 this.SetClickStatu(); new System.Threading.Thread(() => { System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime); //设置非点击后的状态 this.SetNotClickStatu(); }) { IsBackground = true }.Start(); } /// /// 设置点击后的状态 /// public void SetClickStatu() { if (this.oldBackgroundColor == 0) { this.oldBackgroundColor = this.BackgroundColor; } this.BackgroundColor = UserCenterColor.Current.ButtonClickColor; } /// /// 设置非点击后的状态 /// public void SetNotClickStatu() { Application.RunOnMainThread(() => { //设置不选择状态 this.BackgroundColor = oldBackgroundColor; }); } } }