Example #1
0
        /// <summary>
        /// Creates the actual VNC or RDP client control.
        /// </summary>
        private void initSubControl()
        {
            Program.AssertOnEventThread();

            //When switch to RDP from VNC, if RDP IP is empty, do not try to switch.
            if (String.IsNullOrEmpty(rdpIP) && !UseVNC && RemoteConsole != null)
            {
                return;
            }

            bool wasFocused = false;

            this.Controls.Clear();

            Size oldSize = new Size(1024, 768);

            // Kill the old client.
            if (RemoteConsole != null)
            {
                oldSize    = RemoteConsole.DesktopSize;
                wasFocused = RemoteConsole.ConsoleControl != null && RemoteConsole.ConsoleControl.Focused;
                RemoteConsole.DisconnectAndDispose();
                RemoteConsole    = null;
                this.vncPassword = null;
            }

            // Reset
            haveTriedLoginWithoutPassword = false;

            if (UseVNC || String.IsNullOrEmpty(rdpIP))
            {
                this.AutoScroll        = false;
                this.AutoScrollMinSize = new Size(0, 0);

                vncClient = new VNCGraphicsClient(this);

                vncClient.UseSource          = UseSource;
                vncClient.DesktopResized    += ResizeHandler;
                vncClient.Resize            += ResizeHandler;
                vncClient.ErrorOccurred     += ErrorHandler;
                vncClient.ConnectionSuccess += ConnectionSuccess;
                vncClient.Dock = DockStyle.Fill;
            }
            else
            {
                if (rdpClient == null)
                {
                    if (this.ParentForm is FullScreenForm)
                    {
                        oldSize = ((FullScreenForm)ParentForm).contentPanel.Size;
                    }
                    this.AutoScroll        = true;
                    this.AutoScrollMinSize = oldSize;

                    rdpClient = new RdpClient(this, oldSize, ResizeHandler);

                    rdpClient.OnDisconnected += new EventHandler(parentVNCTabView.RdpDisconnectedHandler);
                }
            }

            if (RemoteConsole != null && RemoteConsole.ConsoleControl != null)
            {
                RemoteConsole.KeyHandler    = this.KeyHandler;
                RemoteConsole.SendScanCodes = !this.sourceIsPV;
                RemoteConsole.Scaling       = Scaling;
                RemoteConsole.DisplayBorder = this.displayFocusRectangle;
                SetKeyboardAndMouseCapture(autoCaptureKeyboardAndMouse);
                if (wasPaused)
                {
                    RemoteConsole.Pause();
                }
                else
                {
                    RemoteConsole.Unpause();
                }
                ConnectToRemoteConsole();

                if (wasFocused)
                {
                    RemoteConsole.Activate();
                }
            }

            parentVNCTabView.ShowGpuWarningIfRequired();
        }