登录 注册
当前位置:主页 > 资源下载 > 9 > C# Socket聊天室实例

C# Socket聊天室实例

  • 更新:2024-08-13 08:59:56
  • 大小:603KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:C# - 后端
  • 格式:ZIP

资源介绍

namespace ChatNDraw { public partial class ChatNDrawForm : Form { LoginForm _frmLogin = new LoginForm(); SelectRoomForm _frmSelectRoom = new SelectRoomForm(); private List _strokeList = new List(); private List _endgoing = new List(); private bool _drawing = false; private Point _startDraw = new Point(); private Bitmap _buffer = new Bitmap(333, 131); private DateTime _started; public ChatNDrawForm() { InitializeComponent(); Control.CheckForIllegalCrossThreadCalls = false; } private void btnConnect_Click(object sender, EventArgs e) { switch (_frmLogin.ShowDialog()) { case DialogResult.OK://使用的是一个已经存在的账号登录 connection.Host = _frmLogin.txtHost.Text; connection.Port = (int)_frmLogin.numPort.Value; try { connection.Active = true;//连接到服务器端 connection.Login(_frmLogin.txtUserName.Text, _frmLogin.txtPassword.Text); EnableLoginControls(false); } catch(Exception error) { MessageBox.Show(error.Message, "聊天是服务器连接错误!"); } break; case DialogResult.Yes: //创建一个新的用户连接 connection.Host = _frmLogin.txtHost.Text; connection.Port = (int)_frmLogin.numPort.Value; try { connection.Active = true;//连接到服务器端 connection.LoginNew(_frmLogin.User); EnableLoginControls(false); } catch(Exception error) { MessageBox.Show(error.Message, "聊天是服务器连接错误!"); } break; } }