topFormCapture.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Drawing.Text;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using static System.Net.WebRequestMethods;
  11. namespace MOTINOVA_MC_Test
  12. {
  13. public partial class topFormCapture : Form
  14. {
  15. Point point; //鼠标按下时的点
  16. bool isMoving = false;//标识是否拖动
  17. public topFormCapture()
  18. {
  19. InitializeComponent();
  20. this.FormBorderStyle = FormBorderStyle.None;//无边框
  21. this.StartPosition = FormStartPosition.Manual;//手工指定位置
  22. this.ShowInTaskbar = false;//在任务栏不显示图标
  23. this.TopMost = true;//置顶显示
  24. this.BackColor = Color.White;//背景色
  25. this.StartPosition = FormStartPosition.Manual;
  26. int xWidth = SystemInformation.PrimaryMonitorSize.Width;//获取显示器屏幕宽度
  27. int yHeight = SystemInformation.PrimaryMonitorSize.Height;//高度
  28. this.Location= new Point(xWidth / 2 - this.Width / 2, 10);
  29. }
  30. private void topFormCapture_Load(object sender, EventArgs e)
  31. {
  32. }
  33. private void topFormCapture_MouseDown(object sender, MouseEventArgs e)
  34. {
  35. point = e.Location;//按下的点
  36. isMoving = true;//启动拖动
  37. }
  38. private void topFormCapture_MouseMove(object sender, MouseEventArgs e)
  39. {
  40. if (e.Button == MouseButtons.Left && isMoving)
  41. {
  42. Point pNew = new Point(e.Location.X - point.X, e.Location.Y - point.Y);
  43. //Location = new Point(Location.X + pNew.X, Location.Y + pNew.Y);
  44. Location += new Size(pNew);
  45. }
  46. }
  47. private void topFormCapture_MouseUp(object sender, MouseEventArgs e)
  48. {
  49. isMoving = false;//停止
  50. }
  51. /// <summary>
  52. /// 双击截图
  53. /// </summary>
  54. /// <param name="sender"></param>
  55. /// <param name="e"></param>
  56. private void pictureBox1_DoubleClick(object sender, EventArgs e)
  57. {
  58. string PdName = Class_Motor_Ver.Mode + "_" + Class_Motor_Ver.SN;
  59. if (Form1.myFtp.IsNetConnected == true)
  60. {
  61. string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
  62. //检查路径
  63. if (Form1.myFtp.DirectoryExist("\\", Form1.ServerPath) == false)
  64. {
  65. Form1.myFtp.MakeDir(Form1.ServerPath);
  66. }
  67. if (Form1.myFtp.DirectoryExist(Form1.ServerPath, DataNow) == false)
  68. {
  69. Form1.myFtp.MakeDir(Form1.ServerPath + "\\" + DataNow);
  70. }
  71. if (Form1.myFtp.DirectoryExist(Form1.ServerPath + "\\" + DataNow, PdName) == false)
  72. {
  73. Form1.myFtp.MakeDir(Form1.ServerPath + "\\" + DataNow + "\\" + PdName);
  74. }
  75. //截图
  76. string PIC_SaveFileName = "";
  77. int ScreenWidth = SystemInformation.PrimaryMonitorSize.Width;//获取显示器屏幕宽度
  78. int ScreenHeight = SystemInformation.PrimaryMonitorSize.Height;//高度
  79. Bitmap bit = new Bitmap(ScreenWidth, ScreenHeight);//实例化一个和窗体一样大的bitmap
  80. Graphics g = Graphics.FromImage(bit);
  81. g.CopyFromScreen(0, 0, 0, 0, new Size(ScreenWidth, ScreenHeight));//保存整个窗体为图片
  82. PIC_SaveFileName = Form1.LocalPath + "\\" + "MotorRunTest" + "\\" + PdName + "_测功记录_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png";
  83. bit.Save(PIC_SaveFileName);
  84. //上传图片
  85. bool result1 = Form1.myFtp.UploadFile(PIC_SaveFileName, Form1.ServerPath + "\\" + DataNow + "\\" + PdName);
  86. if (result1 == true)
  87. {
  88. MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  89. }
  90. else
  91. {
  92. MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  93. }
  94. }
  95. else
  96. {
  97. MessageBox.Show("服务器断开!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  98. }
  99. }
  100. /// <summary>
  101. ///
  102. /// </summary>
  103. /// <param name="sender"></param>
  104. /// <param name="e"></param>
  105. private void label_ServerStatus_MouseHover(object sender, EventArgs e)
  106. {
  107. // 创建the ToolTip
  108. ToolTip toolTip1 = new ToolTip();
  109. // 设置显示样式
  110. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  111. toolTip1.InitialDelay = 50;//事件触发多久后出现提示
  112. toolTip1.ReshowDelay = 50;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  113. toolTip1.ShowAlways = true;//是否显示提示框
  114. // 设置伴随的对象
  115. string info = "";
  116. if (Form1.myFtp.IsNetConnected == true)
  117. info = "网络已连接";
  118. else
  119. info = "网络断开";
  120. toolTip1.SetToolTip(this.label_ServerStatus, info);//设置提示内容
  121. }
  122. }
  123. }