void _evt_srv_OnConnect(bool blConnected, string vIpPorts) { for (int i = 0; i < gv.Rows.Count; i++) { string _key = string.Format("{0}:{1}:", gv.Rows[i].Cells["ip"].Value, gv.Rows[i].Cells["port"].Value); if (!vIpPorts.StartsWith(_key)) { continue; } string[] _arr = vIpPorts.Split(':'); _RowIndex = i; clsConnects _en = _lst[_RowIndex]; DataGridViewRow _dr = gv.Rows[_RowIndex]; if (blConnected) { _en.clientPort = _arr[2]; _en.isConnect = true; _en.Connected = Image.FromFile(_imgPath + @"Images\grid\connect_16.png"); } else { _en.clientPort = ""; _en.isConnect = false; _en.Connected = Image.FromFile(_imgPath + @"Images\grid\connect_16no.png"); } gv.InvalidateRow(_RowIndex); } }
private void gv_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { _RowIndex = -1; return; // 内容行 } string _fld = ""; if (e.ColumnIndex > -1) { _fld = gv.Columns[e.ColumnIndex].Name; } if (_fld != "Listen") { _RowIndex = -2; return; // 操作列 } _RowIndex = e.RowIndex; // 当前行 gv.CurrentRow clsConnects _en = _lst[_RowIndex]; DataGridViewRow _dr = gv.Rows[_RowIndex]; if (_en.isListen) // 正在侦听 { _en.isListen = false; _en.Listen = Image.FromFile(_imgPath + @"Images\grid\listen_16no.png"); //_dr.Cells["isListen"].Value = false; //_dr.Cells["Listen"].Value = Image.FromFile(_imgPath + @"Images\grid\listen_16no.png"); _bo_srv.Stop(_en.ip, _en.port); // 停止侦听 } else { _en.isListen = true; _en.Listen = Image.FromFile(_imgPath + @"Images\grid\listen_16.png"); _bo_srv.Listen(_en.ip, _en.port); // 启动侦听 } gv.InvalidateRow(_RowIndex); string _msg = string.Format("{0}", e.RowIndex + 1); this.lb_msg.Text = _msg; }
public static List <clsConnects> doGetDatas(string vIP, int vPort = 5000, int vNumber = 50) { List <clsConnects> _lst = new List <clsConnects>(); clsConnects _en = null; for (int i = 0; i < vNumber; i++) { _en = new clsConnects(); _en.isListen = false; _en.ip = vIP;// "192.168.56.1"; _en.port = vPort + i; _en.id = i.ToString(); _en.isConnect = false; _en.Listen = Image.FromFile(_imgPath + @"Images\grid\listen_16no.png"); _en.Connected = Image.FromFile(_imgPath + @"Images\grid\connect_16no.png"); _lst.Add(_en); } return(_lst); }