亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C# WindowsForm程序同時啟動多個窗口類

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

C# WindowsForm程序同時啟動多個窗口類,具體內(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>
  /// 多窗口同時啟動類
  /// <remarks>繼承ApplicationContext的原因是Application.Run(ApplicationContext context);參數(shù)的需要</remarks>
  /// <remarks>另一個是關(guān)閉同時啟動的窗口</remarks>
  /// </summary>
  class MultiFormApplictionStart : ApplicationContext
  {
    private void onFormClosed(object sender, EventArgs e)
    {
      if (Application.OpenForms.Count == 0)
      {
        ExitThread();
      }
    }
    public MultiFormApplictionStart()
    {
      /*
       *里面添加啟動的窗口
       */
      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)用這個類即可

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

運行后的截圖如下:

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

相關(guān)文章

最新評論