Program.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. namespace DayOf1440
  7. {
  8. static class Program
  9. {
  10. public static List<Form> formList = new List<Form>();
  11. /// <summary>
  12. /// The main entry point for the application.
  13. /// </summary>
  14. [STAThread]
  15. static void Main()
  16. {
  17. Application.EnableVisualStyles();
  18. Application.SetCompatibleTextRenderingDefault(false);
  19. Application.Run(new MainForm());
  20. }
  21. /// <summary>
  22. /// new a Form object
  23. /// </summary>
  24. /// <param name="type"></param>
  25. /// <returns></returns>
  26. internal static Form getInstance(Type type)
  27. {
  28. Form currentForm = null;
  29. foreach (Form formItem in formList)
  30. {
  31. if (formItem.GetType() == type)
  32. {
  33. currentForm = formItem;
  34. currentForm.Activate();
  35. break;
  36. }
  37. }
  38. if (currentForm == null)
  39. {
  40. object obj = Activator.CreateInstance(type);
  41. if (obj is Form)
  42. {
  43. currentForm = obj as Form;
  44. currentForm.Show();
  45. }
  46. }
  47. return currentForm;
  48. }
  49. }
  50. }