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

这是我的代码

4

1 回答 1

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
于 2013-05-22T08:11:41.240 回答