启动时隐藏单一表单 [英] Single Form Hide on Startup

查看:14
本文介绍了启动时隐藏单一表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个表单的应用程序,在 Load 方法中我需要隐藏该表单.

I have an application with one form in it, and on the Load method I need to hide the form.

表单会在需要时自行显示(想想 Outlook 2003 样式的弹出窗口),但我无法弄清楚如何在加载时隐藏表单而不会出现混乱.

The form will display itself when it has a need to (think along the lines of a outlook 2003 style popup), but I can' figure out how to hide the form on load without something messy.

有什么建议吗?

推荐答案

我是从 C# 来的,但在 vb.net 中应该非常相似.

I'm coming at this from C#, but should be very similar in vb.net.

在您的主程序文件中,在 Main 方法中,您将拥有如下内容:

In your main program file, in the Main method, you will have something like:

Application.Run(new MainForm());

这会创建一个新的主窗体并将应用程序的生命周期限制为主窗体的生命周期.

This creates a new main form and limits the lifetime of the application to the lifetime of the main form.

但是,如果您删除 Application.Run() 的参数,则应用程序将在不显示任何表单的情况下启动,您可以随意显示和隐藏表单.

However, if you remove the parameter to Application.Run(), then the application will be started with no form shown and you will be free to show and hide forms as much as you like.

与其在 Load 方法中隐藏表单,不如在调用 Application.Run() 之前初始化表单.我假设表单上将有一个 NotifyIcon 以在任务栏中显示一个图标 - 即使表单本身尚不可见,也可以显示该图标.从 NotifyIcon 事件的处理程序调用 Form.Show()Form.Hide() 将分别显示和隐藏表单.

Rather than hiding the form in the Load method, initialize the form before calling Application.Run(). I'm assuming the form will have a NotifyIcon on it to display an icon in the task bar - this can be displayed even if the form itself is not yet visible. Calling Form.Show() or Form.Hide() from handlers of NotifyIcon events will show and hide the form respectively.

这篇关于启动时隐藏单一表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆