How to have an invisible start up form?

前端 未结 7 2086
眼角桃花
眼角桃花 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:22

    Here is another way that I've found to do this.

    Set the form properties with

    ShowInTaskbar = False
    

    Then in the form's constructor add

    WindowState = FormWindowState.Minimized
    

    This is very easy to implement and works with no flicker. In my case I also use a NotifyIcon to access the program from the notification tray and just set

    WindowState = FormWindowState.Normal
    Show()
    BringToFront()
    

    In the Notify_MouseClick event handler.

    To hide the form again after displaying it, just minimizing again doesn't quite do the job. In my case I use the Form_Closing event and just hide the form.

    Hide()
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-17 17:25

    Try this:

    Sub New()
        MyBase.SetVisibleCore(False)
    End Sub
    
    0 讨论(0)
  • 2020-12-17 17:44

    Put this in the form's Shown event

    Me.Visible = False
    
    0 讨论(0)
  • 2020-12-17 17:44

    The easiest way is to set the opacity of the form to 0%. When you want it to appear, set it back to 100%

    0 讨论(0)
  • 2020-12-17 17:46

    Just to throw out a completely different approach, have you considered not using the overload of Application.Run() that takes (and automatically shows) a Form? If you use the one that passes in an ApplicationContext (or more tyoically, your own subclass of ApplicationContext) then you can choose what your behavior is. See here for more details:

    http://msdn.microsoft.com/en-us/library/ms157901

    0 讨论(0)
提交回复
热议问题