BaseForm.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace KeepScreenLight.Pages
  11. {
  12. /// <summary>
  13. /// base form
  14. /// </summary>
  15. public partial class BaseForm : Form
  16. {
  17. public BaseForm()
  18. {
  19. InitializeComponent();
  20. }
  21. private void BaseForm_Load(object sender, EventArgs e)
  22. {
  23. }
  24. /// <summary>
  25. /// Form之间跳转
  26. /// </summary>
  27. /// <param name="type"></param>
  28. /// <returns></returns>
  29. internal static Form Go(Type type)
  30. {
  31. Form currentForm = null;
  32. foreach (Form formItem in Program.formList)
  33. {
  34. if (formItem.GetType() == type)
  35. {
  36. currentForm = formItem;
  37. currentForm.Activate();
  38. break;
  39. }
  40. }
  41. if (currentForm == null)
  42. {
  43. object obj = Activator.CreateInstance(type);
  44. if (obj is Form)
  45. {
  46. currentForm = obj as Form;
  47. currentForm.Show();
  48. }
  49. }
  50. return currentForm;
  51. }
  52. }
  53. }