BaseForm.cs 2.6 KB

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