示例#1
0
        /// <summary>
        /// </summary>
        /// <remarks>
        /// Initially double-buffering was enabled..
        /// However, in the case of double-buffering, it is necessary to update the whole screen every time.
        /// This is very slow.
        /// Therefore, double-buffering is invalidated and I draw only difference.
        /// </remarks>
        public VncControl()
        {
            InitializeComponent();

            m_handle            = this.Handle;
            m_last              = new PointerEventParameter();
            m_lastPointerSendDt = new DateTime();
            m_encodeList        = new List <List <VncEncodeAbstract> >();
            m_prevSize          = new Size();
            m_needsRedraw       = false;
            m_prevConnected     = false;

            // Set keyboard event
            this.PreviewKeyDown += (s, e) =>
            {
                switch (e.KeyData)
                {
                case Keys.Tab:
                case Keys.Up:
                case Keys.Down:
                case Keys.Left:
                case Keys.Right:
                    // Do not move the focus even if you press the key.
                    e.IsInputKey = true;
                    break;
                }
            };
            this.KeyPress += (s, e) =>
            {
                if (m_client != null && m_client.Connected)
                {
                    // for text
                    m_client.WriteKeyEvent(VncEnum.KeyEventDownFlag.KeyDown, (uint)e.KeyChar);
                    m_client.WriteKeyEvent(VncEnum.KeyEventDownFlag.KeyUp, (uint)e.KeyChar);
                    e.Handled = true;
                }
            };
            this.KeyDown += (s, e) =>
            {
                if (m_client != null && m_client.Connected)
                {
                    uint key = VncWindowsKeyMap.GetVncKey((uint)e.KeyCode);
                    if (key != 0)
                    {
                        // for special key
                        m_client.WriteKeyEvent(VncEnum.KeyEventDownFlag.KeyDown, key);
                        e.Handled = true;
                    }
                }
            };
            this.KeyUp += (s, e) =>
            {
                if (m_client != null && m_client.Connected)
                {
                    uint key = VncWindowsKeyMap.GetVncKey((uint)e.KeyCode);
                    if (key != 0)
                    {
                        // for special key
                        m_client.WriteKeyEvent(VncEnum.KeyEventDownFlag.KeyUp, key);
                        e.Handled = true;
                    }
                }
            };

            // If this is not set, changing the size will not erase existing pictures.
            this.ResizeRedraw = true;

            // Set mouse event
            this.MouseWheel += mouseEvent;
            this.MouseDown  += mouseEvent;
            this.MouseUp    += mouseEvent;
            this.MouseMove  += mouseEvent;
        }