public void Info(string msg) { view.BeginInvoke(new Action(() => { item.ForeColor = Color.Black; item.Text = msg; })); }
private void updateListStock(ListView list) { // list.Items.Clear(); list.Update(); // In case there is databinding list.Refresh(); // Redraw items foreach (Stock stock in stockRequests) { string[] row = { stock._id, stock._id_order, stock.isbn, stock.quantity.ToString(), stock.accepted.ToString() }; ListViewItem item = new ListViewItem(row); if (list.InvokeRequired) { list.BeginInvoke((MethodInvoker) delegate() { list.Items.Add(item); }); } else { list.Items.Add(item); } } }
public void Repaint(bool isDelay = false) { if (!list.InvokeRequired) { return; } var cur = g.engine.currentSound.ID.ToString(); list.BeginInvoke((Action) delegate() { foreach (ListViewItem item in list.Items) { if (cur == item.SubItems[0].Text) { item.BackColor = isDelay ? Color.Green : Color.LightBlue; item.ForeColor = Color.Black; } else { item.BackColor = Color.White; item.ForeColor = Color.Black; } } }); }
public CustomerOrderHistory(Customer customer) { InitializeComponent(); CreateMyListView(); listener = db.CreateQueryForListener("orders", "CustomerID", customer.CustomerID).Listen( snapshot => { orders = new List <Order>(); foreach (DocumentSnapshot documentSnapshot in snapshot.Documents) { Order o = documentSnapshot.ConvertTo <Order>(); o.OrderID = documentSnapshot.Id; orders.Add(o); } try { //orders.Sort((x, y) => x.Status.CompareTo(y.Status)); if (orders != null) { orders = orders.OrderBy(order => order.Status).ToList(); listView1.BeginInvoke(new Action(() => { refreshOrdersList(); })); } } catch {} }); }
public void DoAppend(LoggingEvent loggingEvent) { try { if (listView == null) { return; } string[] msg = { loggingEvent.Level.Name, loggingEvent.LocationInformation.ClassName, loggingEvent.LocationInformation.MethodName, loggingEvent.RenderedMessage }; var listViewItem = new ListViewItem(msg); lock (lockObject) { if (listView == null) { return; } var del = new Action <ListViewItem>(s => { listView.BeginUpdate(); listView.Items.Add(s); listView.EndUpdate(); }); listView.BeginInvoke(del, listViewItem); } } catch (Exception ex) { string exception = ex.ToString(); } }
public static void LoadModule(DataTable dt, ListView lsv, string str) { lsv.Items.Clear(); if (dt != null && dt.Rows.Count > 0) { DataTable dt1 = null; if (str.Trim().Length > 0) { try { string s = "TITLE like '%" + str + "%'"; dt1 = dt.Select(s).CopyToDataTable(); } catch { dt1 = null; } if (dt1 == null || dt1.Rows.Count <= 0) { return; } foreach (DataRow dr in dt1.Rows) { ListViewItem lvi = new ListViewItem(); string type = dr["CoType"].ToString(); string code = dr["Code"].ToString(); string title = dr["Title"].ToString(); string titlelx = dr["TitleLx"].ToString(); lvi.Text = code; lvi.SubItems.AddRange(new string[] { title, titlelx, type }); lsv.BeginInvoke(new Action(() => { lsv.Items.Add(lvi); })); } } } }
//return resault to mainform public void WriteToForm() { try { MainForm Main = Application.OpenForms[FormName] as MainForm; TextBox CCom = Application.OpenForms[FormName].Controls[Ctrl_Compare] as TextBox; TextBox CEcu = Application.OpenForms[FormName].Controls[Ctrl_Euclid] as TextBox; TextBox CDot = Application.OpenForms[FormName].Controls[Ctrl_DotMult] as TextBox; Label Status = Application.OpenForms[FormName].Controls[Ctrl_Answer] as Label; //+listviewer ListView CFingers = Application.OpenForms[FormName].Controls["FingerList"] as ListView; // CCom.BeginInvoke(new Chang_Text(Change_Text_Method), CCom, Answer_Compare.ToString()); CEcu.BeginInvoke(new Chang_Text(Change_Text_Method), CEcu, Answer_Euclid.ToString()); CDot.BeginInvoke(new Chang_Text(Change_Text_Method), CDot, Answer_Dot_Product.ToString()); if (Answer != null) { } else { Answer = "Leap Motion Not Online"; } CFingers.BeginInvoke(new Chang_List(Change_Text_Method), CFingers, Answer_Fingers); Status.BeginInvoke(new Chang_Lab(Change_Text_Method), Status, Answer); } catch { MessageBox.Show("Cannot Find Form Or Controller!!!"); } }
private void updateListStock(ListView list) { foreach (Stock stock in stockRequests) { string[] row = { stock._id_order, stock.isbn, stock.quantity.ToString() }; ListViewItem item = new ListViewItem(row); if (list.InvokeRequired) { list.BeginInvoke((MethodInvoker) delegate() { list.Items.Add(item); }); } else { list.Items.Add(item); } } }
/**************************************************************************************************/ private void SetNewRelativePMH(ListView lv, PastMedicalHistory pmh) { if (pmh != null) { if (lv.InvokeRequired) { lv.BeginInvoke(new NewRelativePmhCallback(SetNewRelativePMH), lv, pmh); } else { foreach (ListViewItem lvi in lv.Items) { if (lvi.Tag != null) { Person p = (Person)(lvi.Tag); if (pmh.RelativeOwningPMH != null) { if (p == pmh.RelativeOwningPMH) { lvi.SubItems[5].Text = pmh.GerSummaryText(); break; } } } } } } }
/// <summary> /// Adds one event to list-box. /// </summary> /// <param name="Event">Event to be added.</param> /// <remarks>See <see cref="IListener.OnEvent">IListener.OnEvent</see> /// for more detail.</remarks> public void OnEvent(IEvent Event) { // Use BeginInvoke for case this method is called from different thread than // the _progressBar's owner (otherwise application would hang here). // Asynchronous version is used for case that thread is blocked. _listView.BeginInvoke(new UpdateListboxDelegate(UpdateListbox), new object[] { Event }); }
// 로그를 출력합니다. public void print(Log type, string format, params Object[] args) { if (logActive_ == false) { this.consolePrint(format, args); return; } // API조회 로그가 너무 많아서 분석에 방해됨. if (type == Log.API조회) { this.consolePrint(format, args); return; } string message = String.Format(format, args); //파일로 기록 남기고, list출력 this.consolePrint(format, args); fileWrite(type, message); if (listView_.InvokeRequired) { listView_.BeginInvoke(new Action(() => printLog(type, message))); } else { printLog(type, message); } }
private void updateListBook(ListView list) { foreach (Book book in books) { string[] row = { book.isbn, book.title, book.author, book.year.ToString(), book.publisher, book.price.ToString() + "€", book.stock.ToString() }; ListViewItem item = new ListViewItem(row); if (list.InvokeRequired) { list.BeginInvoke((MethodInvoker) delegate() { list.Items.Add(item); }); } else { list.Items.Add(item); } } }
/// <summary> /// Handle ARP packets /// </summary> /// <param name="packet">The EthernetDatagram</param> /// <param name="arp">The ArpDatagram to parse</param> public static void HandleARP(Packet packet, ArpDatagram arp, ref UInt64 frame_id, object[] ctrl) { ListViewItem item = new ListViewItem(frame_id.ToString()); frame_id++; List <string> packet_info = new List <string>(); ListView frames = (ListView)ctrl[0]; EthernetDatagram ethernet = packet.Ethernet; packet_info.Add(packet.Timestamp.ToString("hh:mm:ss.fff tt")); packet_info.Add(arp.SenderProtocolIpV4Address.ToString()); packet_info.Add(arp.TargetProtocolIpV4Address.ToString()); packet_info.Add(ethernet.Source.ToString()); packet_info.Add(ethernet.Destination.ToString()); packet_info.Add("ARP"); packet_info.Add(arp.Length.ToString()); // update UI if (item != null) { item.SubItems.AddRange(packet_info.ToArray()); object[] param = new object[2]; param[0] = frames; object[] o = new object[3]; o[0] = item; o[1] = ctrl[1]; o[2] = packet; param[1] = o; frames.BeginInvoke(new ParserHelper.UIHandlerEx(ParserHelper.UpdateFrameUI), param); } }
// public override void WriteLine(string value) // { // if (_textbox.InvokeRequired) // { // WriteLineCallBack writeLineCallBack = WriteLine; // _textbox.Invoke(writeLineCallBack, value); // } // else // { // if (_textbox.Lines.Length > 1000) // _textbox.Text = string.Empty; // _textbox.AppendText(DateTime.Now + "\t" + value + Environment.NewLine); // _textbox.ScrollToCaret(); // } // // Util.LogHelper.Write(value); // } public override void WriteLine(string value) { if (_listView.InvokeRequired) { WriteLineCallBack writeLineCallBack = WriteLine; if (_listView == null || _listView.IsDisposed) { _listView = new ListView(); return; } _listView.BeginInvoke(writeLineCallBack, value); } else { if (_listView.Items.Count > 2000) { _listView.Items.Clear(); } var item = new ListViewItem { Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") }; item.SubItems.Add(value); _listView.Items.Add(item); item.EnsureVisible(); // _textbox.AppendText(DateTime.Now + "\t" + value + Environment.NewLine); // _textbox.ScrollToCaret(); Utils.LogHelper.Write(value); } }
public void Set(RecvPacket p) { if (_listView.InvokeRequired) // 別スレッドから呼び出された場合 { _listView.BeginInvoke(new MethodInvoker(() => Set(p))); } else { var item = _listView.Items.Add(Util.Mac2Str(p.Mac[(int)Sd.Dst])); item.SubItems.Add(Util.Mac2Str(p.Mac[(int)Sd.Src])); item.SubItems.Add(p.Type.ToString()); item.SubItems.Add(p.Protocol.ToString()); item.SubItems.Add(Util.Ip2Str(p.Ip[(int)Sd.Src])); item.SubItems.Add(Util.Ip2Str(p.Ip[(int)Sd.Dst])); item.SubItems.Add(p.Port[(int)Sd.Src].ToString()); item.SubItems.Add(p.Port[(int)Sd.Dst].ToString()); item.SubItems.Add(p.Len.ToString()); item.SubItems.Add(p.Squence.ToString()); item.SubItems.Add(p.Ack.ToString()); item.SubItems.Add(Util.Flg2Str(p.Flg)); item.Tag = Util.Mac2Str(p.Mac[(int)Sd.Dst]); //自動スクロール var rect = _listView.ClientRectangle; //ListViewの高さ取得 var bounds = _listView.Items[0].Bounds; //1行の高さ取得 var row = rect.Height / bounds.Height; //表示されている行数取得 var top = _listView.Items.Count - row; //1行目のItemIndex if (_listView.TopItem.Index == top) { //最下行が表示されているので、自動スクロールする _listView.EnsureVisible(_listView.Items.Count - 1); } } }
internal void AddListViewItem(ListViewItem listItem) { Action action = () => _target.Items.Add(listItem); Delegate asDelegate = action; var handle = _target.BeginInvoke(asDelegate); _target.EndInvoke(handle); }
/// <summary> /// Handle IPV4 packets, including TCP and UDP packets /// </summary> /// <param name="packet">The IpV4Datagram to parse</param> public static void HandleIPV4(Packet packet, IpV4Datagram ip, ref UInt64 frame_id, object[] ctrl) { ListViewItem item = new ListViewItem(frame_id.ToString()); frame_id++; List <string> packet_info = new List <string>(); ListView frames = (ListView)ctrl[0]; EthernetDatagram ethernet = packet.Ethernet; switch (ip.Protocol) { case IpV4Protocol.Udp: { UdpDatagram udp = ip.Udp; packet_info.Add(packet.Timestamp.ToString("hh:mm:ss.fff tt")); packet_info.Add(ip.Source + ":" + udp.SourcePort); packet_info.Add(ip.Destination + ":" + udp.DestinationPort); packet_info.Add(ethernet.Source.ToString()); packet_info.Add(ethernet.Destination.ToString()); packet_info.Add("UDP"); packet_info.Add(udp.Length.ToString()); break; } case IpV4Protocol.Tcp: { TcpDatagram tcp = ip.Tcp; packet_info.Add(packet.Timestamp.ToString("hh:mm:ss.fff tt")); packet_info.Add(ip.Source + ":" + tcp.SourcePort); packet_info.Add(ip.Destination + ":" + tcp.DestinationPort); packet_info.Add(ethernet.Source.ToString()); packet_info.Add(ethernet.Destination.ToString()); packet_info.Add("TCP"); packet_info.Add(tcp.Length.ToString()); break; } default: { item = null; break; } } // update UI if (item != null) { item.SubItems.AddRange(packet_info.ToArray()); object[] param = new object[2]; param[0] = frames; object[] o = new object[3]; o[0] = item; o[1] = ctrl[1]; o[2] = packet; param[1] = o; frames.BeginInvoke(new ParserHelper.UIHandlerEx(ParserHelper.UpdateFrameUI), param); } }
public void Tick() { if (!_list.IsHandleCreated) { return; } _list.BeginInvoke(new MethodInvoker(delegate { // Execute the pre-queue items. _list.BeginUpdate(); while (_preQueue.Count > 0) { _preQueue.Dequeue().Invoke(); } _list.EndUpdate(); // Execute the normal queue items. System.Threading.Timer t = null; t = new System.Threading.Timer(o => { if (_list.IsHandleCreated) { _list.BeginInvoke(new MethodInvoker(delegate { _list.BeginUpdate(); while (_queue.Count > 0) { _queue.Dequeue().Invoke(); } _list.EndUpdate(); })); } t.Dispose(); }, null, HighlightingContext.HighlightingDuration, System.Threading.Timeout.Infinite); })); }
/// <summary> /// 跨线程更新UI界面,更新列表项,i=1表示添加列表项,i=2表示移除列表项 /// </summary> /// <param name="item"></param> /// <param name="i">i=1表示添加列表项,i=2表示移除列表项</param> private void UserlistUpdate(ListViewItem item, int j) { if (UserList.InvokeRequired) { while (!UserList.IsHandleCreated) { if (UserList.Disposing || UserList.IsDisposed) { return; } } listviewupdateProc add = new listviewupdateProc(UserlistUpdate); UserList.BeginInvoke(add, new object[] { item, j }); } else { if (j == 1) { bool flag = true; for (int i = 0; i < UserList.Items.Count; i++) { if (item.SubItems[1].Text == UserList.Items[i].SubItems[1].Text) { if (item.SubItems[0].Text != UserList.Items[i].SubItems[0].Text || item.SubItems[2].Text != UserList.Items[i].SubItems[2].Text || item.Tag != UserList.Items[i].Tag) { flag = true; UserList.Items[i].Remove(); } else { flag = false; } } } if (flag) { UserList.Items.Add(item); } } else if (j == 2) { for (int i = 0; i < UserList.Items.Count; i++) { if (item.SubItems[1].Text == UserList.Items[i].SubItems[1].Text) { UserList.Items[i].Remove(); } } } else { return; } } }
public static void listViewEditItemColor(ListView varListView, int varRow, Color varColor) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewEditItemColor(varListView, varRow, varColor))); } else { varListView.Items[varRow].BackColor = varColor; } }
public static void listViewAddItem(ListView varListView, ListViewItem item) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewAddItem(varListView, item))); } else { varListView.Items.Add(item); } }
public static void listViewEditItem(ListView varListView, int varRow, int varColumn, string varText) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewEditItem(varListView, varRow, varColumn, varText))); } else { varListView.Items[varRow].SubItems[varColumn].Text = varText; } }
public static void listViewAddColumn(ListView varListView, string varColumnName, int varColumnSize) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewAddColumn(varListView, varColumnName, varColumnSize))); } else { varListView.Columns.Add(varColumnName, varColumnSize, HorizontalAlignment.Left); } }
public static void listViewClearColumns(ListView varListView) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new ListViewHandler(listViewClearColumns), new object[] { varListView }); } else { varListView.Clear(); } }
public static void listViewChangeHeaderStyle(ListView varListView, ColumnHeaderStyle varColumnHeaderStyle) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewChangeHeaderStyle(varListView, varColumnHeaderStyle))); } else { varListView.HeaderStyle = varColumnHeaderStyle; } }
public static void UpdatePriceList(RealTimeData rtd) { RealTimeData = rtd; //MethodInvoker mi = new MethodInvoker(UpdateRealTimeListView); if (priceList != null && priceList.IsHandleCreated) { //priceList.BeginInvoke(mi); //priceChangedtDelegate.Invoke(rtd); priceList.BeginInvoke(priceChangedtDelegate, rtd); } }
//Delete item by key (name) public static void listViewDelItem(ListView varListView, string key) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewDelItem(varListView, key))); } else { varListView.Items.RemoveByKey(key); } }
//Clear items public static void listViewItemsClear(ListView varListView) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewItemsClear(varListView))); } else { varListView.Items.Clear(); } }
//Add item row public static void listViewAddItemRange(ListView varListView, string s, string[] row) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewAddItemRange(varListView, s, row))); } else { ListViewItem item = new ListViewItem(s); varListView.Items.Add(item).SubItems.AddRange(row); } }
//Add item by string public static void listViewAddItem(ListView varListView, string text) { if (varListView.InvokeRequired) { varListView.BeginInvoke(new MethodInvoker(() => listViewAddItem(varListView, text))); } else { ListViewItem item = new ListViewItem(text); varListView.Items.Add(item); } }
public void setListViewItemSubItemText(ListView in_me, int and_me, int set_me, string to_me) { if(in_me.InvokeRequired) { in_me.BeginInvoke(new setListViewItemSubItemTextDelegate(setListViewItemSubItemText), new Object[] {in_me,and_me,set_me,to_me}); } else { lock(in_me) { in_me.Items[and_me].SubItems[set_me].Text = to_me; } } }
public void setListViewItemBackColor(ListView in_me, int set_me, System.Drawing.Color to_me) { if(in_me.InvokeRequired) { in_me.BeginInvoke(new setListViewItemBackColorDelegate(setListViewItemBackColor), new Object[] {in_me,set_me,to_me}); } else { lock(in_me) { in_me.Items[set_me].BackColor = to_me; } } }