Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. private void pbResim_MouseMove(object sender, MouseEventArgs e)
  2. {
  3. Point point = pbResim.PointToClient(Cursor.Position);
  4. Point unscaled_p = new Point();
  5. if (kontrol==0)
  6. {
  7. karsıPcHeight = pbResim.Height;
  8. karsıPcWidth = pbResim.Width;
  9. kontrol = 1;
  10. }
  11. int w_c =karsıPcWidth;
  12. int h_c =karsıPcHeight;
  13. int w_i = pbResim.Width;
  14. int h_i = pbResim.Height;
  15.  
  16. float imageRatio = (w_i) / (float)h_i;
  17. float containerRatio = w_c / (float)h_c;
  18. Socket soket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  19. soket.Connect(IPAddress.Parse(karsiIP), 14533);
  20. byte[] gonderilcek;
  21. if (imageRatio >= containerRatio)
  22. {
  23. // horizontal image
  24. float scaleFactor = w_c/(float) w_i;
  25. float scaledHeight = h_i*scaleFactor;
  26. // calculate gap between top of container and top of image
  27. float filler = Math.Abs(h_c - scaledHeight)/2;
  28. unscaled_p.X = (int) (point.X*scaleFactor);
  29. unscaled_p.Y = (int) ((point.Y - filler)*scaleFactor);
  30. gonderilcek =
  31. Encoding.UTF8.GetBytes(unscaled_p.X.ToString() + ":" + unscaled_p.Y.ToString() + "|MouseMove");
  32.  
  33. }
  34. else
  35. {
  36. // vertical image
  37. float scaleFactor = h_c/(float) h_i;
  38. float scaleFactorw = w_c / (float)w_i;
  39. float scaledWidth = w_i*scaleFactor;
  40. float filler = Math.Abs(w_c - scaledWidth)/2;
  41. unscaled_p.X = (int)(point.X * scaleFactorw);
  42. unscaled_p.Y = (int) (point.Y*scaleFactor);
  43. gonderilcek =
  44. Encoding.UTF8.GetBytes(unscaled_p.X.ToString() + ":" + unscaled_p.Y.ToString() + "|MouseMove");
  45. }
  46.  
  47. soket.Send(gonderilcek);
  48. soket.Close();
  49. }
  50.  
  51. private void pbResim_MouseUp(object sender, MouseEventArgs e)
  52. {
  53. byte[] gonderilcek = null;
  54.  
  55. if (e.Button == System.Windows.Forms.MouseButtons.Left)
  56. gonderilcek = Encoding.UTF8.GetBytes("Left:MouseUp");
  57.  
  58. else if (e.Button == System.Windows.Forms.MouseButtons.Right)
  59. gonderilcek = Encoding.UTF8.GetBytes("Right:MouseUp");
  60.  
  61. else
  62. return;
  63. Socket soket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  64. soket.Connect(IPAddress.Parse(karsiIP), 14533);
  65. soket.Send(gonderilcek);
  66. soket.Close();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement