欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# WindowsForm程序同時(shí)啟動(dòng)多個(gè)窗口類

 更新時(shí)間:2021年04月12日 11:46:05   作者:菜鳥葫蘆娃  
這篇文章主要為大家詳細(xì)介紹了C# WindowsForm程序同時(shí)啟動(dòng)多個(gè)窗口類,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

C# WindowsForm程序同時(shí)啟動(dòng)多個(gè)窗口類,具體內(nèi)容如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MVCProject
{
  /// <summary>
  /// 多窗口同時(shí)啟動(dòng)類
  /// <remarks>繼承ApplicationContext的原因是Application.Run(ApplicationContext context);參數(shù)的需要</remarks>
  /// <remarks>另一個(gè)是關(guān)閉同時(shí)啟動(dòng)的窗口</remarks>
  /// </summary>
  class MultiFormApplictionStart : ApplicationContext
  {
    private void onFormClosed(object sender, EventArgs e)
    {
      if (Application.OpenForms.Count == 0)
      {
        ExitThread();
      }
    }
    public MultiFormApplictionStart()
    {
      /*
       *里面添加啟動(dòng)的窗口
       */
      var formList = new List<Form>(){
      new DJControl(), 
      new DJView()
    };
      foreach (var item in formList)
      {
        item.FormClosed += onFormClosed;
      }
      foreach (var item in formList)
      {
        item.Show();
      }
    }
  }
}

最后在Program的類中調(diào)用這個(gè)類即可

  static class Program
  {
    /// <summary>
    /// 應(yīng)用程序的主入口點(diǎn)。
    /// </summary>
    [STAThread]
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new MultiFormApplictionStart());
    }
  }

運(yùn)行后的截圖如下:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論