MainForm.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Ionic.Zip;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.IO.Compression;
  10. using System.Net;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Windows.Forms;
  15. using System.Xml;
  16. namespace MAutoUpdate
  17. {
  18. public partial class MainForm : Form
  19. {
  20. UpdateWork updateWork;
  21. public MainForm(UpdateWork _updateWork)
  22. {
  23. InitializeComponent();
  24. updateWork = _updateWork;
  25. var res = _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc;
  26. var temp = WebRequest.Create(res);
  27. var stream = temp.GetResponse().GetResponseStream();
  28. using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default))
  29. {
  30. string text = reader.ReadToEnd();
  31. this.lblContent.Text = text;
  32. }
  33. //foreach (var item in _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc.Split('$'))
  34. //{
  35. // this.lblContent.Text = this.lblContent.Text + item + Environment.NewLine;
  36. //}
  37. }
  38. #region 让窗体变成可移动
  39. [DllImport("user32.dll")]
  40. public static extern bool ReleaseCapture();
  41. [DllImport("user32.dll")]
  42. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  43. [DllImport("User32.dll")]
  44. private static extern IntPtr WindowFromPoint(Point p);
  45. public const int WM_SYSCOMMAND = 0x0112;
  46. public const int SC_MOVE = 0xF010;
  47. public const int HTCAPTION = 0x0002;
  48. private IntPtr moveObject = IntPtr.Zero; //拖动窗体的句柄
  49. private void PNTop_MouseDown(object sender, MouseEventArgs e)
  50. {
  51. if (moveObject == IntPtr.Zero)
  52. {
  53. if (this.Parent != null)
  54. {
  55. moveObject = this.Parent.Handle;
  56. }
  57. else
  58. {
  59. moveObject = this.Handle;
  60. }
  61. }
  62. ReleaseCapture();
  63. SendMessage(moveObject, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  64. }
  65. #endregion
  66. /// <summary>
  67. /// 如果以后更新,则将更新程序关闭
  68. /// </summary>
  69. /// <param name="sender"></param>
  70. /// <param name="e"></param>
  71. private void btnUpdateLater_Click(object sender, EventArgs e)
  72. {
  73. Application.Exit();
  74. }
  75. private void btnUpdateNow_Click(object sender, EventArgs e)
  76. {
  77. this.Visible = false;//隐藏当前窗口
  78. UpdateForm updateForm = new UpdateForm(updateWork);
  79. if (updateForm.ShowDialog() == DialogResult.OK)
  80. {
  81. Application.Exit();
  82. }
  83. }
  84. private void btnIgnore_Click(object sender, EventArgs e)
  85. {
  86. updateWork.IgnoreThisVersion();
  87. Application.Exit();
  88. }
  89. }
  90. }