/// <summary> /// Run the login dialog to initiate the TFMS Client GUI /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { LoginDialog login = new LoginDialog(); DialogResult result; do { result = login.ShowDialog(); if (result == DialogResult.OK) { // get the user's name, IP address, and port number from the LoginDialog name = login.name; serverAddress = login.serverAddr; // create a new TFMS_Client object myClient = new TFMS_Client(serverPort, name); // create the TFMS_Client delegates myClient.loginReceived += new TFMS_MessageRecieved(handleLogon); myClient.logoffReceived += new TFMS_MessageRecieved(handleLogoff); myClient.listReceived += new TFMS_MessageRecieved(handleList); myClient.dataReceived += new TFMS_MessageRecieved(handleMessage); myClient.disconnectDetected += new TFMS_MessageRecieved(myClient_disconnectDetected); } else if (result == DialogResult.Cancel) { this.Close(); return; } } while (myClient == null || !myClient.connect(serverAddress)); // set the form title to show the user's login name this.Text = name; this.Visible = true; this.WindowState = FormWindowState.Maximized; }
/// <summary> /// If a client is running and the server has disappeared, alert the user /// </summary> /// <param name="dataReceived">the TFMS_Data object indicating the server was lost</param> private void myClient_disconnectDetected(TFMS_Data msg) { myClient = null; MessageBox.Show("The server has been closed or has crashed. Please restart the server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); }