如何有一个无形的启动窗体? [英] How to have an invisible start up form?

查看:20
本文介绍了如何有一个无形的启动窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它是项目解决方案的一部分.在这个项目中,我希望它启动表单时不可见,但在此表单的托盘中仍然有一个通知图标.

I have an application that is a part of a solution of projects. In this project I would like for it to start up form to be invisible, but still have a notification icon in the tray visible for this form.

我知道将 me.hide 添加到 form_load 中是行不通的.我尝试添加一个实例化启动表单的模块,并将其设置为启动对象.虽然那也没有用.我已经没有办法让这种形式隐形了.有人可以帮忙吗?我正在使用 VB.NET.

I know that adding me.hide into the form_load doesn't work. I tried adding a module that instantiates the startup form and I set it as the startup object. Although that didn't work either. I am running out of ideas to have this form invisible. Could anyone help out? I am using VB.NET.

推荐答案

将此粘贴​​到您的表单代码中:

Paste this in your form code:

Protected Overrides Sub SetVisibleCore(ByVal value As Boolean)
    If Not Me.IsHandleCreated Then
        Me.CreateHandle()
        value = False
    End If
    MyBase.SetVisibleCore(value)
End Sub

有效的方式是,由 Application 类完成的第一个显示表单的请求,此代码将 Visible 属性重写回 False.在此之后表单将正常运行,您可以调用 Show() 使其可见,并调用 Close() 关闭它,即使它从不可见.请注意,Load 事件在您显示之前不会触发,因此请确保将事件处理程序中的任何代码(如果有)移动到构造函数或此覆盖.

The way that works is that the very first request to show the form, done by the Application class, this code overrides the Visible property back to False. The form will behave as normal after this, you can call Show() to make it visible and Close() to close it, even when it was never visible. Note that the Load event doesn't fire until you show it so be sure to move any code in your event handler for it, if any, to the constructor or this override.

这篇关于如何有一个无形的启动窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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