private void OnDisconnect(string host) { this.Invoke(new Action(() => { TBText.AppendText($"Disconnect : {host}" + Environment.NewLine); })); }
private void BTStart_Click(object sender, EventArgs e) { TBText.AppendText("正在监听:" + TBPort.Text + "\n"); tcpServer = new TcppServer(int.Parse(TBPort.Text), ReceiveMessage, OnConnect, OnDisconnect); tcpServer?.Start(); }
private void OnConnect(string host) { this.Invoke(new Action(() => { TBText.AppendText($"Connect : {host}" + Environment.NewLine); CBHost.Items.Add(host); LBConnect.Text = tcpServer.ClientsCount().ToString(); })); }
private void ReceiveMessage(string host, TcpDataModel data) { this.Invoke(new Action(() => { if (data.Type == 1000) { string s = Encoding.UTF8.GetString(data.Data); int l = s.Length; TBText.AppendText(host + " : " + s); TBText.AppendText(Environment.NewLine); } })); }
private void DGVList_Select(int index) { if (index >= 0 && index < DGVList.RowCount) { string id = DGVList.Rows[index].Cells["COLId"].Value.ToString(); ClipboardData data = ClipboardDataMan.Get(id); if (data != null) { TBText.Clear(); PBImage.Image = null; DGVData.Rows.Clear(); DGVData.Columns.Clear(); //显示信息大小 TSSLDataSize.Text = ByteConvertTool.Fmt(data.Size); //设置富文本 //if (data.RichText != null) //{ // try // { // using (Stream s = new MemoryStream()) // { // s.Position = 0; // s.Write(data.RichText, 0, data.RichText.Length); // s.Position = 0; // RTBRich.LoadFile(s, RichTextBoxStreamType.RichText); // } // } // catch (Exception e) { } //} //设置纯文本 if (data.Text != null) { //TCData.SelectTab("TPText"); TBText.AppendText(data.Text); } //设置表格 if (data.Text != null) { string[] rows = data.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (var _r in rows) { string[] _d = _r.Split('\t'); if (ListTool.HasElements(_d)) { if (DGVData.Columns.Count < _d.Length) { for (int i = DGVData.Columns.Count; i < _d.Length; i++) { DGVData.Columns.Add($"DGVData_COL{i}", $"{i + 1}"); } } DGVData.Rows.Add(_d); } } } //设置图片 if (data.Image != null) { //TCData.SelectTab("TPImage"); PBImage.Image = data.Image; PBImage.Update(); } } } }