ListBox控件字体刷新颜色提示,GridControl和Label刷新提示
#region 刷新ListBox界面信息
private void RefreshDistributedListbox(string msg, StateType type)
{
if (this.listBoxControl_Distributed.Items.Count > 0 &&
this.listBoxControl_Distributed.Items[0].ToString().Contains(msg))
{
return;
}
switch (type)
{
case StateType.SUCCESS:
msg = $"{this.GetCurrentTimeByHHmmss()}->[成功]{msg}";
break;
case StateType.FAIL:
msg = $"{this.GetCurrentTimeByHHmmss()}->[失败]{msg}";
break;
case StateType.ERR:
msg = $"{this.GetCurrentTimeByHHmmss()}->[错误]{msg}";
break;
case StateType.TIPS:
msg = $"{this.GetCurrentTimeByHHmmss()}->[提示]{msg}";
break;
default:
break;
}
if (this.listBoxControl_Distributed.InvokeRequired)
{
this.Invoke(new Action(() =>
{
if (this.listBoxControl_Distributed.Items.Count > 500) this.listBoxControl_Distributed.Items.RemoveAt(500);
this.listBoxControl_Distributed.Items.Insert(0, msg);
}
));
}
else
{
if (this.listBoxControl_Distributed.Items.Count > 500) this.listBoxControl_Distributed.Items.RemoveAt(500);
this.listBoxControl_Distributed.Items.Insert(0, msg);
}
}
#endregion
#region 枚举
public enum StateType
{
SUCESS,
FAIL,
ERR,
TIPS
}
#endregion
#region 刷新listbox颜色
private void ListBoxControl_Distributed_DrawItem(object sender, ListBoxDrawItemEventArgs e)
{
if (e.Index >= 0)
{
string message = this.listBoxControl_Distributed.Items[e.Index].ToString();
if (message.Contains("[成功]"))
e.Appearance.ForeColor = Color.Green;
else if (message.Contains("[失败]"))
e.Appearance.ForeColor = Color.Red;
else if (message.Contains("[错误]"))
e.Appearance.ForeColor = Color.Red;
else if (message.Contains("[提示]"))
e.Appearance.ForeColor = Color.Blue;
}
}
#endregion
#region 刷新GridControl
private void RefreshGridControl(DevExpress.XtraGrid.GridControl gridControl, DevExpress.XtraGrid.Views.Grid.GridView gridView, object obj)
{
if (this.InvokeRequired)
{
this.Invoke(new Action(() => {
gridControl.DataSource = obj;
gridView.BestFitColumns();
}));
}
else
{
gridControl.DataSource = obj;
gridView.BestFitColumns();
}
}
#endregion
#region 刷新Label
private void RefreshLabel(DevExpress.XtraEditors.LabelControl label, string msg)
{
if (this.InvokeRequired)
this.Invoke(new Action(() => { label.Text = msg; }));
else
label.Text = msg;
}
#endregion
本文来自博客园,作者:云辰,转载请注明原文链接:https://www.cnblogs.com/yunchen/p/13575628.html

浙公网安备 33010602011771号