using Shared; using HDL_ON.UI.CSS; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.Stan { /// /// 电池百分比控件(高为25) /// public class BatteryPersentControl : NormalFrameLayout { #region ■ 变量声明___________________________ /// /// 电池百分比显示的值 /// private NormalViewControl btnBatteryView = null; /// /// 进度条 /// private NormalViewControl btnProgress = null; /// /// 图标控件 /// private IconViewControl btnIcon = null; #endregion #region ■ 初始化_____________________________ /// /// 电池百分比控件(高为25) /// public BatteryPersentControl() { //以图片的计算方法计算高度 this.Height = this.GetPictrueRealSize(25); this.Width = this.GetPictrueRealSize(24) + Application.GetRealWidth(30 + 4); } /// /// 初始化控件 /// /// 是否在右边显示百分比 public void InitControl(bool showPersent = true) { this.btnIcon = new IconViewControl(24); btnIcon.UnSelectedImagePath = "Public/BatteryEnough.png"; this.AddChidren(btnIcon); //电池百分比 if (showPersent == true) { this.btnBatteryView = new NormalViewControl(30, 16, true); btnBatteryView.X = btnIcon.Right + Application.GetRealWidth(4); btnBatteryView.Y = btnIcon.Y + (btnIcon.Height - Application.GetRealHeight(16)) / 2; btnBatteryView.TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel; btnBatteryView.TextColor = CSS_Color.PromptingColor1; this.AddChidren(btnBatteryView); } //进度条控件 this.btnProgress = new NormalViewControl(this.GetPictrueRealSize(15), this.GetPictrueRealSize(8), false); btnProgress.X = this.GetPictrueRealSize(4); btnProgress.Gravity = Gravity.CenterVertical; btnProgress.BackgroundColor = CSS_Color.PromptingColor1; this.AddChidren(btnProgress); } #endregion #region ■ 一般方法___________________________ /// /// 百分比值 /// /// public void SetValue(decimal i_value) { int myWidth = (int)((i_value / 100) * this.GetPictrueRealSize(15)); if (this.btnBatteryView != null) { this.btnBatteryView.Text = i_value + "%"; } this.btnProgress.Width = myWidth; if (i_value <= 20) { //变红色 this.btnProgress.BackgroundColor = 0xfff62f48; this.btnIcon.UnSelectedImagePath = "Public/BatteryNot.png"; } else { //变灰色 this.btnProgress.BackgroundColor = CSS_Color.PromptingColor1; this.btnIcon.UnSelectedImagePath = "Public/BatteryEnough.png"; } } #endregion } }