Me.Hide功能似乎不起作用

时间:2015-11-28 12:41:28

标签: vb.net forms hide

我正在制作一个程序,需要在启动后隐藏自己。 我一直这样做我相信在VB 2008,2010。 但在VS 2015中,Me.Hide 似乎不起作用。我对VB.NET有很好的了解,但我找不到解决方案。用Google搜索,查看代码等。

以下是代码:

Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.Hide()
End Sub

此外,当我把它放入计时器时似乎工作。但这不是我的解决方案,因为我有时需要显示表单。

2 个答案:

答案 0 :(得分:3)

应始终在LOAD事件之外使用Me.Hide。 你可以把它放在SHOWN活动中。 但是,无论如何,为什么不在设计时将属性设置为MINIMIZED = TRUE甚至OPACITY = 0?你会有同样的效果。

甚至可以在设计时将表单的可见性设置为false。

答案 1 :(得分:0)

实现这一目标的一种方法是汉斯提到如果你不希望表单可见,不要调用Show()方法。

  1. 向项目添加一个类,并将一个Shared Sub Main添加到该类
  2. 在项目的属性中,通过取消选中“启用应用程序框架”复选框来关闭应用程序框架。
  3. 在项目的属性中,将启动对象设置为Sub Main
  4. 在Sub Main中使用类似以下的代码:

    Public Class Program
        Public Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
    
            'This will run any code in the forms constructor (Sub New)
            'This line must appear AFTER the two lines above.
            Dim startUpForm As New Form1()
    
            'This will start the application without showing the form.  The
            'form won't show in the task bar either.
            'You must provide some mechanism to show the form later, such as a 
            'tray icon
            Application.Run()
        End Sub
    End Class
    
相关问题