using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Common; using Infragistics.Win.UltraWinEditors; namespace MeterModuleLibrary { public partial class ucWeightCarTJXJG : UserControl { /// /// 记录当前的颜色,在线程中窑调用下面的setControl方法前 /// 可先判断当前的颜色与显示颜色是否一致 /// 若一致则可不调用setControl,不一致再调用 /// public bool isGreenWgt = true; public bool isGrennExceed = true; public ucWeightCarTJXJG() { InitializeComponent(); } /// /// 默认加载窗格线 /// /// /// private void ucWeightCarTJXJG_Load(object sender, EventArgs e) { tableLayoutPanelWeigtAndType.CellBorderStyle = (TableLayoutPanelCellBorderStyle)BorderStyle.FixedSingle; } #region 线程中赋值的控件需使用委托 private delegate void UpdateUIEventHander(object sender, UpdateUIArgs args); //自定义事件用来从线程中更新控件的值 public class UpdateUIArgs : EventArgs { public string textValue { get; private set; } public UpdateUIArgs(string textValue) { this.textValue = textValue; } } /// /// 重量稳定 /// /// public void setStable(bool bGreen) { if (!PbCache.isLockWgt) { if (picStable.IsHandleCreated) { isGreenWgt = bGreen; string sValue = isGreenWgt ? "green" : "red"; picStable.Invoke(new UpdateUIEventHander(UpdateUI_Method), picStable, new UpdateUIArgs(sValue)); } } } /// txtWeightType /// 实时写入重量 /// PbCache.isLockWgt 重量未锁定则可写入,否则调用了也不会写入 /// /// 重量信息 public void setWgt(double db) { if (!PbCache.isLockWgt) { if (txtWeight.IsHandleCreated) { txtWeight.Invoke(new UpdateUIEventHander(UpdateUI_Method), txtWeight, new UpdateUIArgs(db.ToString("0.00") + "")); } } } /// /// 写入重量类型 /// PbCache.isLockWgt 重量未锁定则可写入,否则调用了也不会写入 /// /// 重量信息 public void setWeightType(string db) { if (!PbCache.isLockWgt) { if (txtWeightType.IsHandleCreated) { txtWeightType.Invoke(new UpdateUIEventHander(UpdateUI_Method), txtWeightType, new UpdateUIArgs(db + "")); } } } /// /// 设置重量字体的背景颜色:Lime及NotShow(不显示) /// /// public void setWgtBackColor(bool bLime) { if (!PbCache.isLockWgt) { if (txtWeight.IsHandleCreated) { isGreenWgt = bLime; string sValue = isGreenWgt ? "Lime" : "NotShow"; txtWeight.Invoke(new UpdateUIEventHander(UpdateUIBackColor_Method), txtWeight, new UpdateUIArgs(sValue)); } } } /// /// 设置背景色 /// /// /// private void UpdateUIBackColor_Method(object sender, UpdateUIArgs args) { if (sender is UltraTextEditor) { if (args.textValue == "Lime") { ((UltraTextEditor)sender).Appearance.BackColor = Color.Black; ((UltraTextEditor)sender).Appearance.ForeColorDisabled = Color.Black; } else { //System.Drawing.Color.Transparent;跟随背景色 ((UltraTextEditor)sender).Appearance.BackColor = Color.Transparent; ((UltraTextEditor)sender).Appearance.ForeColorDisabled = Color.Transparent; //((UltraTextEditor)sender).Appearance.BackColor = Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(244)))), ((int)(((byte)(252))))); //((UltraTextEditor)sender).Appearance.ForeColorDisabled = Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(244)))), ((int)(((byte)(252))))); } } } private void UpdateUI_Method(object sender, UpdateUIArgs args) { if(sender is UltraTextEditor) { if (args.textValue == "" || args.textValue == null) { ((UltraTextEditor)sender).Text = "0"; } else { ((UltraTextEditor)sender).Text = args.textValue; } } else if (sender is Button) { if (args.textValue == "red") { ((Button)sender).BackColor = Color.Red; ((Button)sender).ForeColor = Color.White; } else if (args.textValue == "green") { ((Button)sender).BackColor = Color.White; ((Button)sender).ForeColor = Color.Black; } else { ((Label)sender).Text = args.textValue; } } else if (sender is PictureBox) { if (args.textValue == "red") { ((PictureBox)sender).Load(PbCache.path + "\\image\\icon\\不具备.png"); } else { ((PictureBox)sender).Load(PbCache.path + "\\image\\icon\\具备.png"); } } } #endregion } }