private void canvas_MouseMove(object sender, MouseEventArgs e) { if (Mouse.LeftButton.Equals(MouseButtonState.Pressed) && framePassed()) { double x; double y; MyLine line = new MyLine(); x = e.GetPosition(canvas).X; y = e.GetPosition(canvas).Y; if (x > canvas.Width) { x = canvas.Width; } if (y > canvas.Width) { y = canvas.Width; } if (x < 0) { x = 0; } if (y < 0) { y = 0; } //MessageBox.Show(x+" "+y); line.X2 = lastX; line.Y2 = lastY; lastX = x; lastY = y; line.X1 = x; line.Y1 = y; try { line.thickness = (byte)size_Slider.Value; } catch { } if (line.thickness > 20 || line.thickness < 0) { line.thickness = 3; } try { line.rgb = new byte[] { (byte)(red_Slider.Value), (byte)(green_Slider.Value), (byte)(blue_Slider.Value) }; } catch { MessageBox.Show("Only valid values are allowed (0-255)"); } line2 = MyLine.newLine(line.X1, line.Y1, line.X2, line.Y2, line.thickness, line.rgb); canvas.Children.Add(line2); sendLine(line); } }
public void recieveLine(string obj) { try { while (true) { int index = obj.IndexOf('}'); string objtemp = obj.Substring(0, index + 1); MyLine myLine = JsonConvert.DeserializeObject <MyLine>(objtemp); Line line = MyLine.newLine(myLine.X1, myLine.Y1, myLine.X2, myLine.Y2, myLine.thickness, myLine.rgb); canvas.Children.Add(line); if (objtemp.Length == obj.Length) { break; } obj = obj.Substring(index + 1, obj.Length - index - 1); } } catch { } }
public void recieve(string obj) { try { while (true) { int index = obj.IndexOf("}}") + 1; string objtemp = obj.Substring(0, index + 1); Envelope unknown = JsonConvert.DeserializeObject <Envelope>(objtemp); if (unknown.type == "MyLine") { MyLine myLine = JsonConvert.DeserializeObject <MyLine>(unknown.obj.ToString()); Line line = MyLine.newLine(myLine.X1, myLine.Y1, myLine.X2, myLine.Y2, myLine.thickness, myLine.rgb); canvas.Children.Add(line); } else if (unknown.type == "Message") { Message m = JsonConvert.DeserializeObject <Message>(unknown.obj.ToString()); string s = m.user + ": " + m.text + "\n"; chatWindow.Text += s; } else { break; } /* * MyLine l = null; * l = (unknown as MyLine); * if (l==null) * { * MessageBox.Show("This doesn't show"); * } * if (l is MyLine) * { * MessageBox.Show("This doesn't show either???"); * } */ /* * try * { * unknown = unknown as MyLine; * }catch * { * unknown = unknown as Message; * } * if (unknown is MyLine) * { * MessageBox.Show("It's a line"); * } * else if (unknown is Message) * { * MessageBox.Show("It's a message"); * } */ if (objtemp.Length == obj.Length) { break; } obj = obj.Substring(index + 1, obj.Length - index - 1); } } catch { } }