Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Net;
  11. using System.Net.Sockets;
  12. using System.Threading;
  13. namespace WindowsFormsApplication3
  14. {
  15. public partial class Form1 : Form
  16. {
  17. UdpClient uc;
  18. Thread th;
  19. public Form1()
  20. {
  21. InitializeComponent();
  22.  
  23. uc = new UdpClient(55555);
  24. uc.EnableBroadcast = true;
  25. th = new Thread(new ThreadStart(threadrun));
  26. th.Start();
  27.  
  28. }
  29. void threadrun()
  30. {
  31. IPEndPoint iep =new IPEndPoint(IPAddress.Broadcast, 55555);
  32. while (true)
  33. {
  34. byte[] data = uc.Receive(ref iep);
  35.  
  36. Point p = new Point();
  37. p.X = BitConverter.ToInt32(data, 0);
  38. p.Y = BitConverter.ToInt32(data, 4);
  39. lock (bejovo)
  40. {
  41. bejovo.Add(p);
  42. }
  43. }
  44.  
  45. }
  46. List<Point> bejovo = new List<Point>();
  47.  
  48. private void Form1_Load(object sender, EventArgs e)
  49. {
  50.  
  51. }
  52.  
  53. int oldmousex = -1; int oldmousey = -1;
  54. private void Form1_MouseMove_1(object sender, MouseEventArgs e)
  55. {
  56.  
  57. string s = e.X + ";" + e.Y + e.Button;
  58. Graphics gr = CreateGraphics();
  59. //gr.Clear(Color.Black);
  60. //gr.DrawString(s,new Font("Arial",16), Brushes.DarkBlue, (float)e.X, (float)e.Y);
  61. //gr.DrawLine(Pens.Aquamarine,0,0,e.X,e.Y);
  62. //gr.DrawLine(Pens.Lime, Width, 0, e.X, e.Y);
  63. //gr.DrawLine(Pens.Gold, Width, Height, e.X, e.Y);
  64. //gr.DrawLine(Pens.BlueViolet, 0, Height, e.X, e.Y);
  65. //gr.DrawEllipse(Pens.Red,e.X-50,e.Y-50,100,100);
  66. //gr.DrawLine(Pens.Red,e.X,e.Y-80,e.X,e.Y+80);
  67. if ((e.Button & MouseButtons.Left) > 0 && oldmousex > 0)
  68. gr.DrawLine(Pens.Red,oldmousex,oldmousey,e.X,e.Y);
  69. oldmousex = e.X;
  70. oldmousey = e.Y;
  71.  
  72.  
  73.  
  74.  
  75. List<byte> data = new List<byte>();
  76.  
  77. data.AddRange(BitConverter.GetBytes(e.X));
  78. data.AddRange(BitConverter.GetBytes(e.Y));
  79.  
  80.  
  81. uc.Send(data.ToArray(),data.ToArray().Length,new IPEndPoint(IPAddress.Broadcast,5555));
  82.  
  83. }
  84.  
  85. private void timer1_Tick(object sender, EventArgs e)
  86. {
  87. Graphics g = CreateGraphics();
  88. g.Clear(Color.Black);
  89.  
  90. lock (bejovo)
  91. {
  92. foreach (Point p in bejovo)
  93. {
  94. g.DrawEllipse(Pens.Red,p.X-5, p.Y-5,10,10);
  95. }
  96. bejovo.Clear();
  97. }
  98.  
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement