Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在windows启动时不使用窗体运行程序_Vb.net - Fatal编程技术网

Vb.net 在windows启动时不使用窗体运行程序

Vb.net 在windows启动时不使用窗体运行程序,vb.net,Vb.net,基本上我想展示的是: notifyicon.visible=true 我的意思是在windows启动时显示托盘图标,但不应显示程序窗体,我如何实现它 我知道,通过添加到注册表,您可以在启动时运行下面的程序示例 Dim regkey As RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", True) If

基本上我想展示的是:

notifyicon.visible=true

我的意思是在windows启动时显示托盘图标,但不应显示程序窗体,我如何实现它

我知道,通过添加到注册表,您可以在启动时运行下面的程序示例

Dim regkey As RegistryKey
        regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", True)
        If (runonstartupToolStripMenuItem.Checked = True) Then
            ' Add the value in the registry so that the application runs at startup
            regkey.SetValue("Your Application Name", Application.ExecutablePath.ToString())
        Else
            ' Remove the value from the registry so that the application doesn't start
            regkey.DeleteValue("Your Application Name", False)
        End If

但这将运行整个程序,并使窗体显示,除非用户手动启动它,否则我不希望显示该窗体。

将此代码添加到窗体:

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Me.Hide()                    ' <= Required
      Me.ShowInTaskbar = False     ' <= Required
      NotifyIcon1.Visible = True  
      NotifyIcon1.ShowBalloonTip(10000)
 End Sub
Private Sub Form1\u Load(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load

Me.Hide()“我正在使用复选框设置和取消设置:

Private Sub cbStartup_CheckedChanged(sender As Object, e As EventArgs) Handles cbStartup.CheckedChanged
        Dim applicationName As String = Application.ProductName
        Dim applicationPath As String = Application.ExecutablePath

        If cbStartup.Checked = True Then
            Dim regKey As Microsoft.Win32.RegistryKey
            regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
            regKey.SetValue(applicationName, """" & applicationPath & """")
            regKey.Close()
        Else
            Dim regKey As Microsoft.Win32.RegistryKey
            regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
            regKey.DeleteValue(applicationName, False)
            regKey.Close()
        End If
    End Sub

VS 2015上的测试工作在Windows 10 64位上运行。

您需要让应用程序接受至少一个您可以读取的命令行参数,然后决定是否显示表单。您可以将该参数包含在您存储在注册表中的命令行中。您可以向我展示一个示例吗?当用户手动运行应用程序时,它将加载并形成一个什么样的窗体,该窗体将调用我。hide()不会打开窗体,用户必须从notifyicon打开,这似乎不合适,至少在使用“手动打开”时它应该打开窗体,并且通过两种方式它都将调用窗体的事件。加载事件中的loadHide()不会隐藏窗体。很容易找到,只要试试。@HansPassant
Hide()
with
ShowInTaskbar=False
就可以了。这是一个相当讨厌的黑客行为。一定要当心副作用。@HansPassant为什么
是一个相当讨厌的黑客行为
?毕竟,我们真的不想在任务栏上看到表单。