/// <summary> /// Handle local drawing /// </summary> private void canvas_MouseMove(object sender, MouseEventArgs e) { if (_isDrawing && !_previousMousePosition.IsEmpty) { var segment = new PointSegment(_previousMousePosition, e.Location); DrawLine(segment); _udpSender.Send(segment); } _previousMousePosition = e.Location; }
/// <summary> /// Tries to deserialize the data into a <see cref="PointSegment"/>. /// </summary> /// <param name="bytes">The binary data to be deserialized.</param> /// <param name="result">The deserialized <see cref="PointSegment"/> if succeeded.</param> /// <returns>True if succeeded, false if unsuccessful.</returns> private bool TryDeserializePointSegment(byte[] bytes, out PointSegment result) { using (var stream = new MemoryStream(bytes)) { stream.Seek(0, SeekOrigin.Begin); var data = _deserializer.Deserialize(stream); if (data is PointSegment p) { result = p; return(true); } } result = default; return(false); }
/// <summary> /// Draw line on canvas. /// </summary> private void DrawLine(PointSegment segment) { _graphics.DrawLine(_pen, segment.Point1, segment.Point2); }