SetLoadingWindow.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Threading;
  3. using System.Windows.Forms;
  4. namespace UAS_LabelMachine.PublicForm
  5. {
  6. public partial class SetLoadingWindow : Form
  7. {
  8. Thread LoadingThread;
  9. public SetLoadingWindow()
  10. {
  11. InitializeComponent();
  12. }
  13. public SetLoadingWindow(Thread LoadEvent,string Title)
  14. {
  15. InitializeComponent();
  16. LoadingThread = LoadEvent;
  17. Text = Title;
  18. }
  19. private void SetLoadingWindow_Load(object sender, EventArgs e)
  20. {
  21. //设置Loading的大小,启动传递过来的进程
  22. loadingCircle1.OuterCircleRadius = 20;
  23. loadingCircle1.InnerCircleRadius = 12;
  24. loadingCircle1.Active = true;
  25. LoadingThread.ApartmentState = ApartmentState.STA;
  26. LoadingThread.Start();
  27. //在本窗体新建一个进程用来判断传递的进程是否执行结束
  28. Thread t1 = new Thread(SetLoadFinish);
  29. t1.Start();
  30. }
  31. private void SetLoadFinish()
  32. {
  33. while (LoadingThread.IsAlive)
  34. {
  35. }
  36. Close();
  37. }
  38. //在进程结束之前不允许此窗体被关闭
  39. private void SetLoadingWindow_FormClosing(object sender, FormClosingEventArgs e)
  40. {
  41. if (LoadingThread.IsAlive) {
  42. e.Cancel=true;
  43. }
  44. }
  45. private void CancelThread_Click(object sender, EventArgs e)
  46. {
  47. LoadingThread.Abort();
  48. }
  49. }
  50. }