C# 实现窗体启动时隐藏

2023-06-25,,

在某些时候需要实现一个界面的后台程序,程序自动运行,但起初不显示窗体,在满足触发条件时显示,此时需要在运行程序时先自动隐藏窗体。

修改窗体对应的Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading; namespace U8FileTransfer
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new Form1()); // 注释掉默认代码 new Thread(new ThreadStart(() =>
{
          // 满足某种触发条件时显示窗体。
Thread.Sleep(3 * 1000);
Main win = new Main();
win.Show();
})).Start(); Application.Run(); // 运行程序(去掉了 new Form1()参数)
}
}
}

C# 实现窗体启动时隐藏的相关教程结束。

《C# 实现窗体启动时隐藏.doc》

下载本文的Word格式文档,以方便收藏与打印。