BaseForm.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Windows.Forms;
  3. namespace TaskbarGroups.Views
  4. {
  5. /// <summary>
  6. /// Form 基类
  7. /// </summary>
  8. public partial class BaseForm : Form
  9. {
  10. public BaseForm()
  11. {
  12. this.Load += new EventHandler(BaseForm_Load);
  13. this.FormClosed += new FormClosedEventHandler(BaseForm_FormClosed);
  14. InitializeComponent();
  15. }
  16. public void BaseForm_Load(object sender, EventArgs e)
  17. {
  18. Program.formList.Add(this);
  19. }
  20. public void BaseForm_FormClosed(object sender, FormClosedEventArgs e)
  21. {
  22. Program.formList.Remove(this);
  23. }
  24. private void InitializeComponent()
  25. {
  26. this.SuspendLayout();
  27. //
  28. // BaseForm
  29. //
  30. //this.ClientSize = new System.Drawing.Size(1350, 729);
  31. //this.Name = "BaseForm";
  32. //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  33. //this.DoubleClick += new System.EventHandler(this.BaseForm_DoubleClick);
  34. this.ResumeLayout(false);
  35. }
  36. /// <summary>
  37. /// 双击关闭窗体
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. private void BaseForm_DoubleClick(object sender, EventArgs e)
  42. {
  43. Application.Exit();
  44. }
  45. /// <summary>
  46. /// 解决winform刚启动的时候,由于picture 太多闪屏问题
  47. /// </summary>
  48. protected override CreateParams CreateParams
  49. {
  50. get
  51. {
  52. CreateParams cp = base.CreateParams;
  53. cp.ExStyle |= 0x02000000;
  54. return cp;
  55. }
  56. }
  57. /// <summary>
  58. /// Form之间跳转
  59. /// </summary>
  60. /// <param name="type"></param>
  61. /// <returns></returns>
  62. internal static Form Go(Type type)
  63. {
  64. Form currentForm = null;
  65. foreach (Form formItem in Program.formList)
  66. {
  67. if (formItem.GetType() == type)
  68. {
  69. currentForm = formItem;
  70. currentForm.Activate();
  71. break;
  72. }
  73. }
  74. if (currentForm == null)
  75. {
  76. object obj = Activator.CreateInstance(type);
  77. if (obj is Form)
  78. {
  79. currentForm = obj as Form;
  80. currentForm.Show();
  81. }
  82. }
  83. return currentForm;
  84. }
  85. }
  86. }