How to have an invisible start up form?

前端 未结 7 2122
眼角桃花
眼角桃花 2020-12-17 16:43

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 t

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 17:25

    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
    

    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.

提交回复
热议问题