C# Winform同时启动多个窗体类
首先创建一个类,存放将要同时显示的窗体
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同时启动多个窗体类的更多相关文章
- Winform中如何实现父窗体传递数据到子窗体并刷新子窗体
原理:利用委托和事件,本文将以图文并茂的例子讲述,告诉我们So Easy --------------------------------------------------------------- ...
- linux下启动dbca或netmgr类的图形界面报错解决
linux下启动dbca或netmgr类的图形界面报错解决 Xlib: connection to ":0.0" refused by server Xlib: No pro ...
- Qt窗体关闭时,如何自动销毁窗体类对象
Qt窗体关闭时,如何自动销毁窗体类对象 要对你的窗口设置WA_DeleteOnClose属性,默认的情况下关闭窗口仅仅意味着隐藏它 ImgWindow1->setAttribute(Qt ...
- duilib底层机制剖析:窗体类与窗体句柄的关联
转载请说明原出处,谢谢~~ 看到群里朋友有人讨论WTL中的thunk技术,让我联想到了duilib的类似技术.这些技术都是为了解决c++封装的窗体类与窗体句柄的关联问题. 这里是三篇关于thunk技术 ...
- 【Demo 0025】注册/反注册窗体类RegisterClassEx/UnregisterClass
所有窗体在创建前都必须注册窗体类,只有注册的窗体类才被系统认知并允许实例化,换句话说通过注册告诉进程窗体管理器此类窗体的属性如: 背景色,窗体上的鼠标样式以及窗体事件处理函数等; 有一些控件类系统自 ...
- [C#]做服务使用Process启动外部程序没窗体
这几天会到一个需要,要时时侦测文件生成,并上传到Server上,侦测文件生成使用的FileSystemWatch.但是时时运行遇到了问题,程序可能会人为退出或者意外终止,使用一个进程监控程序的监程,也 ...
- JAVA笔记__窗体类/Panel类/Toolkit类
/** * 窗体类 */ public class Main { public static void main(String[] args) { MyFrame m1 = new MyFrame() ...
- WinForm程序启动控制台窗口Console
本文转载:http://blog.csdn.net/oyi319/article/details/5753311 2.WinForm程序和控制台窗口Console 如果你调试过SharpDevelop ...
- WinForm 读取Excel 数据显示到窗体中
最近教学中,需要用到WinForm 读取Excel数据,于是就做了一个简单的,废话不多说,直接codding... //读取Excel的帮助类 class SqExcellHelper { publi ...
随机推荐
- day43 多表查询和pymysql
复习 增删改查全语法 # 增 insert into db1.t1(字段2, 字段1, ..., 字段n)|省略 values (值2, 值1, ..., 值n)|(值1, 值2, ..., 值n)[ ...
- Windbg驱动双机调试环境配置
[由于进入了Windows驱动编程领域第一步就是搭建环境,整个环境来说说难也不难,只是比较麻烦.文章有些地方比较繁琐的,而且别人写的比较好,作为引用参考直接贴连接了.如果你按照我写的一步步完成,很快就 ...
- CentOS7 firewalld防火墙配置
[root@ecs ~]# firewall-cmd --version //查看版本0.3.9 [root@ecs ~]# firewall-cmd --state //查 ...
- [leetcode]6. ZigZag Conversion字符串Z形排列
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- Django formset
一 什么是formset Form组件或ModelForm用于做一个表单验证而formset是用于做多个表单的验证组件,用于做批量操作 二 formset的使用方法 1 设置form信息 class ...
- django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call
Error info: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, ...
- Bootstrap+PHP fileinput 实现多图上传 这是ajax上传,只能单张单张图片地上传
插件及源代码可以在这里下载 http://www.jq22.com/jquery-info5231下面是根据下载的demo进行补充:使用bootstrap界面美观,可预览,可拖拽上传,可配合ajax异 ...
- RIDE 接口自动化请求体参数中文时报错:“UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 9......”
在进行robotframework 接口自动化,在请求体参数中输入中文会报以下错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 ...
- SPS Programming Abrites AVDI or GM MDI
Just information for you to make a wise purchase of GM scan tools for SPS programming: (here, I focu ...
- c++沉思录 学习笔记 第六章 句柄(引用计数指针雏形?)
一个简单的point坐标类 class Point {public: Point():xval(0),yval(0){} Point(int x,int y):xval(x),yval(y){} in ...