/// <summary> /// 用于在listview中显示对应Ip是否在线 /// </summary> /// <param name="lvi">绑定的控件</param> /// <param name="text">在线信息</param> public void ShwMsgforView(ListView lvi, string[] text) { if (lvi.InvokeRequired) { ShwMsgforViewCallBack shwMsgforViewCallBack = ShwMsgforView; lvi.Invoke(shwMsgforViewCallBack, new object[] { lvi, text }); int count = lvi.Items.Count; int rownum = IsExistsItem(text[1], lvi); if (rownum >= 0) { lvi.BeginUpdate(); lvi.Items[rownum].SubItems[1].Text = text[1]; lvi.Items[rownum].SubItems[2].Text = text[0]; if (text[0] == "在线") { lvi.Items[rownum].SubItems[17].Text = Convert.ToString("4"); lvi.Items[rownum].BackColor = System.Drawing.Color.Chartreuse; lvi.Items[rownum].ForeColor = System.Drawing.Color.Red;//字颜色 } else { lvi.Items[rownum].SubItems[17].Text = Convert.ToString("3"); lvi.Items[rownum].BackColor = System.Drawing.Color.Red; //行颜色 lvi.Items[rownum].ForeColor = System.Drawing.Color.CornflowerBlue; //字颜色 } //------------------记录 lvi.EndUpdate(); } else { string[] str = new string[] { (count + 1).ToString(), text[1], text[0], " ", " ", " ", " ", " ", " ", " ", " ", " " }; ListViewItem lit = new ListViewItem(str); lvi.BeginUpdate(); lvi.Items.Add(lit); lvi.EndUpdate(); } } else { } }
public static void ShwMsgforView(ListBox listbox, string text) { if (listbox.InvokeRequired) { ShwMsgforViewCallBack shwMsgforViewCallBack = ShwMsgforView; listbox.Invoke(shwMsgforViewCallBack, new object[] { listbox, text }); } else { listbox.Items.Add(text); listbox.SelectedIndex = listbox.Items.Count - 1; listbox.ClearSelected(); } }