Exemplo n.º 1
0
        /// <summary>
        /// Sends the mouse down event when the user release the mouse button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PictureBox_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Show the coordinate of the mouse in debug window.
            Debug.WriteLine($"Mouse Up at: ({e.X},{e.Y})");

            // Initialize the command as null.
            UserMouseCommand mouseCommand = null;

            // Get the clicked mouse button and initialize the command.
            if (e.Button == MouseButtons.Left)
            {
                mouseCommand = new UserMouseCommand(e.X, e.Y, 0, MouseEventFlag.LeftUp);
            }
            else if (e.Button == MouseButtons.Right)
            {
                mouseCommand = new UserMouseCommand(e.X, e.Y, 0, MouseEventFlag.RightUp);
            }

            // This null check is unnecessary in formal edition, only useful when developing.
            if (mouseCommand != null)
            {
                // Serialize the command.
                MemoryStream ms = new MemoryStream();
                formatter.Serialize(ms, mouseCommand);
                byte[] mouseCommandBytes = ms.GetBuffer();
                ms.Close();

                // Send the command.
                clientSocket.Send(mouseCommandBytes);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the mouse down event when the user roll the mouse wheel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PictureBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Show the coordinate of the mouse in debug window.
            Debug.WriteLine($"Mouse Down at: ({e.X},{e.Y})");

            // Create the mouse move command.
            UserMouseCommand mouseCommand = new UserMouseCommand(e.X, e.Y, 0, MouseEventFlag.Move);

            // This null check is unnecessary in formal edition, only useful when developing.
            if (mouseCommand != null)
            {
                // Serialize the command.
                MemoryStream ms = new MemoryStream();
                formatter.Serialize(ms, mouseCommand);
                byte[] mouseCommandBytes = ms.GetBuffer();
                ms.Close();

                // Send the command.
                clientSocket.Send(mouseCommandBytes);
            }
        }
        private void cmdSendMouseCommand_Click(object sender, RoutedEventArgs e)
        {
            UserMouseCommand mouseCommand = null;

            int mouseX = int.Parse(txtMouseX.Text);
            int mouseY = int.Parse(txtMouseY.Text);

            TextBlock txtMouseCommand = cbMouseCommand.SelectedItem as TextBlock;

            switch (txtMouseCommand.Text)
            {
            case MoveMouse:
                mouseCommand = new UserMouseCommand(mouseX, mouseY, 0, MouseEventFlag.Move);
                break;

            case MouseLeftClick:
                mouseCommand = new UserMouseCommand(mouseX, mouseY, 0, MouseEventFlag.LeftDown | MouseEventFlag.LeftUp);
                break;

            case MouseRightClick:
                mouseCommand = new UserMouseCommand(mouseX, mouseY, 0, MouseEventFlag.RightDown | MouseEventFlag.RightUp);
                break;

            default:
                break;
            }

            MemoryStream    ms        = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(ms, mouseCommand);

            byte[] mouseCommandBytes = ms.GetBuffer();
            ms.Close();

            clientSocket.Send(mouseCommandBytes);
        }