vb.net 如何在后台运行我的应用程序 (VB 2008-10)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17639112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:15:13  来源:igfitidea点击:

How can I run my application in background (VB 2008-10)?

vb.netbackgroundicons

提问by

Sorry if such a question like this has been posted before. How do I make my VB application run in background so that I can click on the hidden icons in the tray of hidden icons (near the clock and the date) of my Windows 7 PC and re-activate it?

抱歉,如果之前已经发布过这样的问题。如何让我的 VB 应用程序在后台运行,以便我可以单击 Windows 7 PC 的隐藏图标托盘中的隐藏图标(靠近时钟和日期)并重新激活它?

I tried to hide my form to do this, but I did not know how to re-activate its window back. On the OnClick()method of my button cmdRunBG, I typed:

我试图隐藏我的表单来执行此操作,但我不知道如何重新激活它的窗口。在OnClick()我的按钮方法上cmdRunBG,我输入:

Me.visible = false

Well, that thing just hid the form. I want it to reallyrun in the background, having an icon in the tray of icons (near the system clock). How do I do that?

好吧,那东西只是隐藏了表格。我希望它真正在后台运行,在图标托盘中(靠近系统时钟)有一个图标。我怎么做?

If you have any clarifications regarding this, please respond.

如果您对此有任何澄清,请回复。

Thanks.

谢谢。

采纳答案by dkar

What you really want is to programmatically minimize your form. Try that:

您真正想要的是以编程方式最小化您的表单。试试看:

Me.WindowState = FormWindowState.Minimized

EDIT:

编辑:

If you want to put the application on system tray, a simple way to do it is the following:

如果要将应用程序放在系统托盘上,一个简单的方法如下:

  1. add a NotifyIcon control to your application and set its properties
  2. add the following code in the Resizeevent of your form:

    If Me.WindowState = FormWindowState.Minimized Then
       Me.Hide()
    End If
    
  3. add the following code in the MouseClickevent of your NotifyIcon:

    If Me.WindowState = FormWindowState.Minimized Then
        Me.Show()
        Me.WindowState = FormWindowState.Normal
    End If
    
  1. 向您的应用程序添加 NotifyIcon 控件并设置其属性
  2. Resize表单的事件中添加以下代码:

    If Me.WindowState = FormWindowState.Minimized Then
       Me.Hide()
    End If
    
  3. MouseClick您的 NotifyIcon 事件中添加以下代码:

    If Me.WindowState = FormWindowState.Minimized Then
        Me.Show()
        Me.WindowState = FormWindowState.Normal
    End If