📄 form2.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace mychat1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private TcpClient server;
string myownip;
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("请输入完整服务器的信息!");
return ;
}
string ip = textBox1.Text;
int port = Convert.ToInt32(textBox2.Text);
try
{
server = new TcpClient(ip, port);
myownip= server.Client.LocalEndPoint.ToString();
byte [] info=Encoding .Unicode .GetBytes (textBox3 .Text + ":我上线了!");
server.Client.Send(info);
}
catch (SocketException)
{
MessageBox.Show("unable to connect to server!", "提示!", MessageBoxButtons.OK);
return;
}
server.Close();
Form main = new Form1 (textBox3 .Text ,ip,port,myownip );
main.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -