private void StopBtn_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to disconnect?", "Disconnect", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (RDCClient.Connected.ToString() == "1") { RDCClient.Disconnect(); } } }
public void Connect(string ip, string username, string password) { try { this.WindowState = FormWindowState.Maximized; RDCClient.Server = ip; RDCClient.UserName = username; IMsTscNonScriptable secured = (IMsTscNonScriptable)RDCClient.GetOcx(); secured.ClearTextPassword = password; RDCClient.DesktopHeight = RDCPanel.Height; RDCClient.DesktopWidth = RDCPanel.Width; RDCClient.Connect(); RDCClient.OnConnecting += RDCClient_OnConnecting; RDCClient.OnConnected += RDCClient_OnConnected; RDCClient.OnDisconnected += RDCClient_OnDisconnected; RDCClient.OnFatalError += RDCClient_OnFatalError; RDCClient.OnLogonError += RDCClient_OnLogonError; RDCClient.OnWarning += RDCClient_OnWarning; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }