扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:crystal编译 来源:yesky 2007年11月14日
关键字:
public void LoadThread() { MethodInvoker mi = new MethodInvoker(this.UpdateListView); string tmp = null; StreamReader sr = File.OpenText("Issue.txt"); while((tmp = sr.ReadLine()) !=null ) { if (tmp =="") break; isu.symbol= Mid(tmp, 0, 4); isu.bid = Mid(tmp, 4, 5); isu.offer = Mid(tmp, 9, 5); isu.volume = Mid(tmp, 16, tmp.Length-16); sendMsg ="\v" + tmp + "\n"; //add send message's head and end char SendDataToAllClient(tmp); this.BeginInvoke(mi); JobDone.WaitOne(); } sr.Close(); fThd.Abort(); } private void SendDataToAllClient(string str) { foreach (Socket s in socketHolder.Values) { if(s.Connected) { Byte[] byteDateLine=ASCII.GetBytes(str.ToCharArray()); s.Send(byteDateLine, byteDateLine.Length, 0); } } } |
public void LoadXmlThread() { MethodInvoker miv = new MethodInvoker(this.UpdateListView); string tmp = null; string xmlString = null; int recordFlg = -1; int textCount =0; xmlString = "\v"+""; XmlTextReader tr = new XmlTextReader("issue.xml"); while(tr.Read()) { switch (tr.NodeType) { case XmlNodeType.Element: if (tr.Name == "Issue") { recordFlg++; if(recordFlg > 0) { textCount=0; xmlString += CreateXmlElement( tr.Name, 2); xmlString += "\n"; SendDataToAllClient(xmlString); xmlString = "\v"+" version='1.0'?>"; this.BeginInvoke(miv); JobDone.WaitOne(); } } if (recordFlg >= 0) { xmlString += CreateXmlElement( tr.Name, 1); tmp = tr.Name; } break; case XmlNodeType.Text: switch(++textCount) { case 1: isu.symbol=tr.Value; break; case 2: isu.bid=tr.Value; break; case 3: isu.offer=tr.Value; break; case 4: isu.volume=tr.Value; break; } xmlString += tr.Value; xmlString += CreateXmlElement(tmp, 2); break; } } fThd.Abort(); } string CreateXmlElement(string elem, int ord) { string tmp = null; if (ord == 1) tmp = String.Format("<{0}>", elem); else tmp = String.Format("", elem); return tmp; } 以下功能演示的是如何设置TcpClient中Listview控件的 BackColor和 Forecolor属性 。 private void UpdateListView() { int ind=-1; for (int i=0; i < this.listView1.Items.Count;i++) { if (this.listView1.Items[i].Text == isu.symbol.ToString()) { ind=i; break; } } if (ind == -1) { ListViewItem newItem new ListViewItem(isu.symbol.ToString()); newItem.SubItems.Add(isu.bid); newItem.SubItems.Add(isu.offer); newItem.SubItems.Add(isu.volume); this.listView1.Items.Add(newItem); int i=this.listView1.Items.IndexOf(newItem); setRowColor(i, System.Drawing.Color.FromArgb(255, 255, 175)); setColColorHL(i, 0, System.Drawing.Color.FromArgb(128,0,0)); setColColorHL(i, 1, System.Drawing.Color.FromArgb(128,0,0)); this.listView1.Update(); Thread.Sleep(300); setColColor(i, 0, System.Drawing.Color.FromArgb(255, 255,175)); setColColor(i, 1, System.Drawing.Color.FromArgb(255, 255, 175)); } else { this.listView1.Items[ind].Text = isu.symbol.ToString(); this.listView1.Items[ind].SubItems[1].Text = (isu.bid); this.listView1.Items[ind].SubItems[2].Text = (isu.offer); this.listView1.Items[ind].SubItems[3].Text = (isu.volume); setColColorHL(ind, 0, System.Drawing.Color.FromArgb(128,0,0)); setColColorHL(ind, 1, System.Drawing.Color.FromArgb(128,0,0)); this.listView1.Update(); Thread.Sleep(300); setColColor(ind, 0, System.Drawing.Color.FromArgb(255,255,175)); setColColor(ind, 1, System.Drawing.Color.FromArgb(255,255,175)); } JobDone.Set(); } private void setRowColor(int rowNum, Color colr ) { for (int i=0; i < this.listView1.Items[rowNum].SubItems.Count;i++) if (rowNum%2 !=0) this.listView1.Items[rowNum].SubItems[i].BackColor = colr; } private void setColColor(int rowNum, int colNum, Color colr ) { if (rowNum%2 !=0) this.listView1.Items[rowNum].SubItems[colNum].BackColor=colr; else this.listView1.Items[rowNum].SubItems[colNum].BackColor = System.Drawing.Color.FromArgb(248, 248,248); if (colNum==0) { this.listView1.Items[rowNum].SubItems[colNum].ForeColor = System.Drawing.Color.FromArgb(128, 0, 64); this.listView1.Items[rowNum].SubItems[colNum].BackColor = System.Drawing.Color.FromArgb(197, 197, 182); } else this.listView1.Items[rowNum].SubItems[colNum].ForeColor = System.Drawing.Color.FromArgb(20, 20,20); } private void setColColorHL(int rowNum, int colNum, Color colr ) { this.listView1.Items[rowNum].SubItems[colNum].BackColor = colr; this.listView1.Items[rowNum].SubItems[colNum].ForeColor = System.Drawing.Color.FromArgb(255,255,255); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者