public void ConnectRDP(RDPServer server) { try { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TabWindow)); this.rdp = new SmartRDP.MyRDP(); ((System.ComponentModel.ISupportInitialize)(this.rdp)).BeginInit(); this.rdp.Dock = System.Windows.Forms.DockStyle.Fill; this.rdp.Enabled = true; this.rdp.Location = new System.Drawing.Point(0, 0); this.rdp.Name = "rdp"; this.rdp.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("rdp.OcxState"))); //this.rdp.Size = new System.Drawing.Size(1264, 986); this.rdp.TabIndex = 10; this.Controls.Add(this.rdp); ((System.ComponentModel.ISupportInitialize)(this.rdp)).EndInit(); rdp.Server = server.Name; rdp.UserName = server.Username; IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx(); secured.ClearTextPassword = server.Password; rdp.Connect(); //修改tab标签 this.Text = server.Name; if (rdp.Connected == 2) { // 如果连上了 则存储这个server server.IsVNC = false; rdpServerManager.saveOrUpdateServer(server); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void ConnectVNC(RDPServer server) { this.vnc = new VncSharp.RemoteDesktop(); this.vnc.AutoScroll = true; this.vnc.AutoScrollMinSize = new System.Drawing.Size(608, 427); this.vnc.Location = new System.Drawing.Point(3, 3); this.vnc.Name = "VNC"; this.vnc.TabIndex = 10; this.vnc.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(this.vnc); this.vnc.ConnectComplete += delegate { // 如果连上了 则存储这个server server.IsVNC = true; rdpServerManager.saveOrUpdateServer(server); this.vnc.Focus(); }; // Get a host name from the user. string host = server.Name; // As long as they didn't click Cancel, try to connect if (host != null) { try { this.vnc.GetPassword = new AuthenticateDelegate(server.getPassword); this.vnc.Connect(host); //修改tab标签 this.Text = server.Name; } catch (VncProtocolException vex) { MessageBox.Show(this, string.Format("Unable to connect to VNC host:\n\n{0}.\n\nCheck that a VNC host is running there.", vex.Message), string.Format("Unable to Connect to {0}", host), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(this, string.Format("Unable to connect to host. Error was: {0}", ex.Message), string.Format("Unable to Connect to {0}", host), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
private void connect_Click(object sender, EventArgs e) { string server = textBox_serverName.Text; string password = textBox_password.Text; string user = textBox_userName.Text; RDPServer rdpServerInfo = new RDPServer(server, user, password); panel_connect.Hide(); if (this.radioButtonRDP.Checked) this.ConnectRDP(rdpServerInfo); else if (this.radioButtonVNC.Checked) this.ConnectVNC(rdpServerInfo); }
public void saveOrUpdateServer(RDPServer server) { RDPServer s = getServerByName(server.Name, server.IsVNC); if (s != null) { if (server.Password != s.Password) s.Password = server.Password; } else { servers.Add(server); } }