MainForm.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Google.Protobuf;
  2. using Newtonsoft.Json.Linq;
  3. using NNanomsg.Protocols;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Security.Cryptography;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using tool;
  15. namespace monitor_main_windows
  16. {
  17. public partial class MainForm : Form
  18. {
  19. //Communicator com;
  20. MonitorMainWindows MonitorMainWindows = null;
  21. public MainForm()
  22. {
  23. InitializeComponent();
  24. }
  25. private void button_open_Click(object sender, EventArgs e)
  26. {
  27. MonitorMainWindows = new MonitorMainWindows();
  28. MonitorMainWindows.Show();
  29. }
  30. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  31. {
  32. MonitorMainWindows?.Uninit();
  33. }
  34. private void button1_MouseHover(object sender, EventArgs e)
  35. {
  36. Button btn = (Button)sender;
  37. // 创建the ToolTip
  38. ToolTip toolTip1 = new ToolTip();
  39. // 设置显示样式
  40. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  41. toolTip1.InitialDelay = 500;//事件触发多久后出现提示
  42. toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  43. toolTip1.ShowAlways = true;//是否显示提示框
  44. // 设置伴随的对象.
  45. toolTip1.SetToolTip(btn, "开始?");//设置提示按钮和提示内容
  46. }
  47. //生成指定长度唯一码
  48. public static string GetUniqueIdentifier(int length)
  49. {
  50. int maxSize = length;
  51. char[] chars = new char[62];
  52. string a;
  53. a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  54. chars = a.ToCharArray();
  55. int size = maxSize;
  56. byte[] data = new byte[1];
  57. var crypto = new RNGCryptoServiceProvider();
  58. crypto.GetNonZeroBytes(data);
  59. size = maxSize;
  60. data = new byte[size];
  61. crypto.GetNonZeroBytes(data);
  62. var result = new StringBuilder(size);
  63. foreach (byte b in data)
  64. {
  65. result.Append(chars[b % (chars.Length - 1)]);
  66. }
  67. if (result[0] >= '0' && result[0] <= '9')
  68. {
  69. return GetUniqueIdentifier(length);
  70. }
  71. return result.ToString();
  72. }
  73. }
  74. }