2013-05-22 28 views
0

我有一個程序路徑..如utorrent和它的PID也。我已經使用vb.net以編程方式實現了這些值。我只想隱藏他們的圖標表單托盤,只是爲了在後臺運行它們,並且如果可能的話,用一個熱鍵附加這個進程來回叫它們。有什麼辦法可以做到這一點。隱藏進程圖標在後臺運行

Option Strict On 
Option Explicit On 
Option Infer Off 

Imports TrayHelper 

Public Class Form1 
    Dim x1, y1 As Single 
    Friend WithEvents lv As New ListView With {.Parent = Me, .Dock = DockStyle.Fill} 


    Private il As New ImageList 
    Dim nxt As Integer 
    Friend WithEvents mnuContextMenu As New ContextMenu() 'Moved this to be declared as global 
    Dim mnuItemHide As New MenuItem() 
    Dim mnuItemExit As New MenuItem() 
    Dim things As List(Of TrayButton) = TrayHelper.Tray.GetTrayButtons() 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     Me.Controls.Add(lv) 
     lv.View = View.Details 


     il.ColorDepth = ColorDepth.Depth32Bit 
     lv.SmallImageList = il 
     lv.Columns.Add("Button Text", 300, HorizontalAlignment.Left) 
     lv.Columns.Add("PID", 50, HorizontalAlignment.Left) 
     lv.Columns.Add("Process Path", 600, HorizontalAlignment.Left) 
     'Dim things As List(Of TrayButton) = TrayHelper.Tray.GetTrayButtons() 
     For Each b As TrayButton In things 
      If b.Icon IsNot Nothing Then 
       il.Images.Add(b.TrayIndex.ToString, b.Icon) 
      Else 
       ' When we can't find an icon, the listview will display this form's one. 
       ' You could try to grab the icon from the process path I suppose. 
       il.Images.Add(b.TrayIndex.ToString, Me.Icon) 
      End If 
      Dim lvi As New ListViewItem(b.Text) 
      lvi.SubItems.Add(b.ProcessIdentifier.ToString) 
      lvi.SubItems.Add(b.ProcessPath) 
      lvi.ImageKey = b.TrayIndex.ToString 
      lv.Items.Add(lvi) 
     Next 
     lv.MultiSelect = False 
     'lv.ContextMenu = mnuContextMenu 'Don`t need to add if done this way 

     lv.FullRowSelect = True 'Added this but, you don`t need it if you don`t want it 


     mnuItemHide.Text = "&Hide" 
     mnuItemExit.Text = "&Exit" 
     mnuContextMenu.MenuItems.Add(mnuItemHide) 
     mnuContextMenu.MenuItems.Add(mnuItemExit) 


     AddHandler mnuItemHide.Click, AddressOf Me.menuItem1_Click 


    End Sub 

    Private Sub lv_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lv.MouseDown 
     If e.Button = Windows.Forms.MouseButtons.Right Then 
      If lv.GetItemAt(e.X, e.Y) IsNot Nothing Then 
       lv.GetItemAt(e.X, e.Y).Selected = True 
       mnuContextMenu.Show(lv, New Point(e.X, e.Y)) 
       mnuItemExit.Visible = True 
       mnuItemHide.Visible = True 

      End If 

     End If 

    End Sub 

    Private Sub menuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 

     Dim txtValue as String 
     txtValue = lv.FocusedItem.SubItems(2).Text 
     Kill(txtValue) 

     Dim txtValue1 As String 
     txtValue1 = lv.FocusedItem.SubItems(0).Text 
     MessageBox.Show(txtValue1 + " has been hidden") 

    End Sub 

End Class 

這是我的代碼

+0

是的,但你有什麼嘗試過,爲什麼失敗? 對於您的問題,這不是一個輕鬆解決問題的方法,您可以嘗試通過找出自己並在失敗時提出問題來付出一點努力。你會學到更多的東西。任何方式。你可能想從這裏開始; http://www.dotnetperls.com/process-start-vbnet –

+0

我已經添加了我所嘗試的至今 – nyxem1

+0

這些程序是否啓動?還是你想寫一個程序,可以隱藏和顯示任意程序的系統托盤圖標? – Adrian

回答

1

要隱藏窗體 - >form1.visible=false
從任務欄隱藏窗體 - >form1.ShowinTaskbar=false
然後去form1 keydown event,並把這個...

If e.Control And e.KeyCode = Keys.Q Then ' ---> activate with Ctrl-Q 
    form1.visible=true 
End If 
+0

我想隱藏其他程序的任務欄圖標,而不是形式... – nyxem1