/// <summary> /// Connect to a VNC Host and determine whether or not the server requires a password. /// </summary> /// <param name="host">The IP Address or Host Name of the VNC Host.</param> /// <param name="display">The Display number (used on Unix hosts).</param> /// <param name="viewOnly">Determines whether mouse and keyboard events will be sent to the host.</param> /// <param name="scaled">Determines whether to use desktop scaling or leave it normal and clip.</param> /// <exception cref="System.ArgumentNullException">Thrown if host is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if display is negative.</exception> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already Connected. See <see cref="VncSharpWpf.RemoteDesktop.IsConnected" />.</exception> public void Connect(string host, int display, bool viewOnly, bool scaled) { // TODO: Should this be done asynchronously so as not to block the UI? Since an event // indicates the end of the connection, maybe that would be a better design. InsureConnection(false); if (host == null) { throw new ArgumentNullException("host"); } if (display < 0) { throw new ArgumentOutOfRangeException("display", display, "Display number must be a positive integer."); } // Start protocol-level handling and determine whether a password is needed vnc = new VncClient(); vnc.ConnectionLost += new EventHandler(VncClientConnectionLost); vnc.ServerCutText += new EventHandler(VncServerCutText); passwordPending = vnc.Connect(host, display, VncPort, viewOnly); desktopPolicy = new VncWpfDesktopPolicy(vnc, this); SetScalingMode(scaled); if (passwordPending) { // Server needs a password, so call which ever method is refered to by the GetPassword delegate. string password = GetPassword(); if (password == null) { // No password could be obtained (e.g., user clicked Cancel), so stop connecting return; } else { Authenticate(password); } } else { // No password needed, so go ahead and Initialize here this.waitLabel.Content = "Connecting to VNC host " + host + "(" + port + ") , please wait... "; Initialize(); } }
/// <summary> /// Connect to a VNC Host and determine whether or not the server requires a password. /// </summary> /// <param name="host">The IP Address or Host Name of the VNC Host.</param> /// <param name="display">The Display number (used on Unix hosts).</param> /// <param name="viewOnly">Determines whether mouse and keyboard events will be sent to the host.</param> /// <param name="scaled">Determines whether to use desktop scaling or leave it normal and clip.</param> /// <exception cref="System.ArgumentNullException">Thrown if host is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if display is negative.</exception> /// <exception cref="System.InvalidOperationException">Thrown if the RemoteDesktop control is already Connected. See <see cref="VncSharpWpf.RemoteDesktop.IsConnected" />.</exception> public void Connect(string host, int display, bool viewOnly, bool scaled) { // TODO: Should this be done asynchronously so as not to block the UI? Since an event // indicates the end of the connection, maybe that would be a better design. InsureConnection(false); if (host == null) throw new ArgumentNullException("host"); if (display < 0) throw new ArgumentOutOfRangeException("display", display, "Display number must be a positive integer."); // Start protocol-level handling and determine whether a password is needed vnc = new VncClient(); vnc.ConnectionLost += new EventHandler(VncClientConnectionLost); vnc.ServerCutText += new EventHandler(VncServerCutText); passwordPending = vnc.Connect(host, display, VncPort, viewOnly); desktopPolicy = new VncWpfDesktopPolicy(vnc, this); SetScalingMode(scaled); if (passwordPending) { // Server needs a password, so call which ever method is refered to by the GetPassword delegate. string password = GetPassword(); if (password == null) { // No password could be obtained (e.g., user clicked Cancel), so stop connecting return; } else { Authenticate(password); } } else { // No password needed, so go ahead and Initialize here this.waitLabel.Content = "Connecting to VNC host " + host + "(" + port + ") , please wait... "; Initialize(); } }