C# WindowsForm程序同時(shí)啟動(dòng)多個(gè)窗口類
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)行后的截圖如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#獲取應(yīng)用程序路徑或Web頁(yè)面目錄路徑
這篇文章介紹了C#獲取應(yīng)用程序路徑或Web頁(yè)面目錄路徑的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05
解決C#獲取鼠標(biāo)相對(duì)當(dāng)前窗口坐標(biāo)的實(shí)現(xiàn)方法
本篇文章是對(duì)在C#中獲取鼠標(biāo)相對(duì)當(dāng)前窗口坐標(biāo)的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C#函數(shù)式程序設(shè)計(jì)之用閉包封裝數(shù)據(jù)的實(shí)現(xiàn)代碼
如果一個(gè)程序設(shè)計(jì)語(yǔ)言能夠用高階函數(shù)解決問(wèn)題,則意味著數(shù)據(jù)作用域問(wèn)題已十分突出。當(dāng)函數(shù)可以當(dāng)成參數(shù)和返回值在函數(shù)之間進(jìn)行傳遞時(shí),編譯器利用閉包擴(kuò)展變量的作用域,以保證隨時(shí)能得到所需要的數(shù)據(jù)2014-03-03
C#實(shí)現(xiàn)關(guān)機(jī)重啟及注銷實(shí)例代碼
這篇文章主要介紹了C#實(shí)現(xiàn)關(guān)機(jī)重啟及注銷實(shí)例代碼,適合新手參考學(xué)習(xí)之用,需要的朋友可以參考下2014-07-07
c# GridControl的模糊查詢實(shí)現(xiàn)代碼
這篇文章主要介紹了c# GridControl的模糊查詢實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-02-02
winform 調(diào)用攝像頭掃碼識(shí)別二維碼的實(shí)現(xiàn)步驟
這篇文章主要介紹了winform 調(diào)用攝像頭掃碼識(shí)別二維碼的實(shí)現(xiàn)步驟,幫助大家更好的理解和學(xué)習(xí)使用winform,感興趣的朋友可以了解下2021-02-02

