首先创建一个类,存放将要同时显示的窗体

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
class MultiFormApplictionStart : ApplicationContext
{
/// <summary>
/// 多窗口同时启动类
/// <remarks>继承ApplicationContext的原因是Application.Run(ApplicationContext context);参数的需要</remarks>
/// <remarks>另一个是关闭同时启动的窗口</remarks>
/// </summary>
private void onFormClosed(object sender, EventArgs e)
{
if (Application.OpenForms.Count == )
{
ExitThread();
}
} public MultiFormApplictionStart()
{
//将要显示的窗体集合
var formList = new List<Form>(){
new Form1(),
new Form2()
}; foreach (var item in formList)
{
item.FormClosed += onFormClosed;
} foreach (var item in formList)
{
item.Show();
}
}
}
}

主程序Program更改为

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MultiFormApplictionStart()); //调用用于显示窗体的类
}
}
}

最终效果图

C# Winform同时启动多个窗体类的更多相关文章

  1. Winform中如何实现父窗体传递数据到子窗体并刷新子窗体

    原理:利用委托和事件,本文将以图文并茂的例子讲述,告诉我们So Easy --------------------------------------------------------------- ...

  2. linux下启动dbca或netmgr类的图形界面报错解决

    linux下启动dbca或netmgr类的图形界面报错解决    Xlib: connection to ":0.0" refused by server Xlib: No pro ...

  3. Qt窗体关闭时,如何自动销毁窗体类对象

    Qt窗体关闭时,如何自动销毁窗体类对象     要对你的窗口设置WA_DeleteOnClose属性,默认的情况下关闭窗口仅仅意味着隐藏它 ImgWindow1->setAttribute(Qt ...

  4. duilib底层机制剖析:窗体类与窗体句柄的关联

    转载请说明原出处,谢谢~~ 看到群里朋友有人讨论WTL中的thunk技术,让我联想到了duilib的类似技术.这些技术都是为了解决c++封装的窗体类与窗体句柄的关联问题. 这里是三篇关于thunk技术 ...

  5. 【Demo 0025】注册/反注册窗体类RegisterClassEx/UnregisterClass

    所有窗体在创建前都必须注册窗体类,只有注册的窗体类才被系统认知并允许实例化,换句话说通过注册告诉进程窗体管理器此类窗体的属性如: 背景色,窗体上的鼠标样式以及窗体事件处理函数等;  有一些控件类系统自 ...

  6. [C#]做服务使用Process启动外部程序没窗体

    这几天会到一个需要,要时时侦测文件生成,并上传到Server上,侦测文件生成使用的FileSystemWatch.但是时时运行遇到了问题,程序可能会人为退出或者意外终止,使用一个进程监控程序的监程,也 ...

  7. JAVA笔记__窗体类/Panel类/Toolkit类

    /** * 窗体类 */ public class Main { public static void main(String[] args) { MyFrame m1 = new MyFrame() ...

  8. WinForm程序启动控制台窗口Console

    本文转载:http://blog.csdn.net/oyi319/article/details/5753311 2.WinForm程序和控制台窗口Console 如果你调试过SharpDevelop ...

  9. WinForm 读取Excel 数据显示到窗体中

    最近教学中,需要用到WinForm 读取Excel数据,于是就做了一个简单的,废话不多说,直接codding... //读取Excel的帮助类 class SqExcellHelper { publi ...

随机推荐

  1. Nginx – rewrite 配置 URL重写及301跳转原理图

    Nginx – rewrite 配置 URL重写 官网:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html 语法:rewrite re ...

  2. oday获取系统最高权限的代码

    import sys,sockettarget = sys.argv[1]shellcode = ("\x6a\x4f\x59\xd9\xee\xd9\x74\x24\xf4\x5b\x81 ...

  3. python argparse(参数解析)模块学习(二)

    转载自:http://www.cnblogs.com/fireflow/p/4841389.html(我去..没转载功能,ctrl + c 和 ctrl + v 得来的,格式有点问题,可去原版看看) ...

  4. c#: WebBrowser控件html代码注入及交互

    主题仍是下载相关. 页面加载完成后,注入html元素,以使能够与主程序交互.并使WebBrowser与js交互,可以实现一些有趣的功能. 欲使WebBrowser与js交互,其所在页面类,须加上[Co ...

  5. blockchain[z]

    https://medium.com/programmers-blockchain/creating-your-first-blockchain-with-java-part-2-transactio ...

  6. Java Token的原理和生成使用机制

    在此之前我们先了解一下什么是Cookie.Session.Token 1.什么是Cookie? cookie指的就是浏览器里面能永久存储数据的一种数据存储功能.cookie由服务器生成,发送给浏览器, ...

  7. 受欢迎的牛[HAOI2006]

    --BZOJ1051 Description 每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 ​ 种关系是具有传递性的,如果A认为B受欢迎, ...

  8. 查看memcached进程

  9. python 数据可视化(matplotlib)

    matpotlib 官网 :https://matplotlib.org/index.html matplotlib 可视化示例:https://matplotlib.org/gallery/inde ...

  10. sqlserver删除临时表中的数据

    select distinct * into #tmptable from tablename drop table tablename select * into tablename from #t ...