namespace WindowsFormsApplication1 { public partial class Form1 : Form { StreamReader sr; StreamWriter sw; TcpClient connection; public Form1() { InitializeComponent(); Button btn1 = new Button(); btn1.Click += button1_Click; } private void Form1_Load(object sender, EventArgs e) { connection = new TcpClient("127.0.0.1", 5000); sr = new StreamReader(connection.GetStream()); sw = new StreamWriter(connection.GetStream()); } private void button2_Click(object sender, EventArgs e) { Thread t2 = new Thread(Reader); t2.Start(connection); } string msg; public void Reader(object o) { TcpClient con = o as TcpClient; if (con == null) { return; } while (true) { msg = sr.ReadLine(); Invoke(new Action(Output)); } } public void Output() { ChatScreen.Text = msg; } string textinput; private void button1_Click(object sender, EventArgs e) { textinput = InputLine.Text; sw.WriteLine(textinput); sw.Flush(); } } }
btn.Click()
WriteLine
Controls.Add(btn1);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)