VB.NET表单操作作为系统托盘 [英] VB.NET form manipulation as system tray

查看:77
本文介绍了VB.NET表单操作作为系统托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Esc 按下时,我有一个表格会最小化托盘图标

I have a form that will minimize on tray icon when Esc is press

Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    If e.KeyCode = Keys.Escape Then
        Me.WindowState = FormWindowState.Minimized
        NotifyIcon1.Visible = True
        Me.Hide()
    End If
End Sub



我想要的是当我按下另一个热键时显示该表格(当表单最小化为系统托盘时,按Ctrl + Q



我发现了这个,但它是在VB6代码中

http ://www.vbforums.com/showthread.php?394845-RESOLVED-Detect-a-Hot-Key-without-looping& highlight = RegisterHotKey [ ^ ]

推荐答案

此CodeProject文章应该可以帮助您启用Hotkey和ShortcutInput用户控制的简单步骤 [ ^ ]
This CodeProject article should help you Simple steps to enable Hotkey and ShortcutInput user control[^]


我会将ProcessCmdKey用于ESC按钮..表单.KeyDown从来没有对我有用;)



I would use ProcessCmdKey for that ESC Button.. Form.KeyDown never worked well for me ;)

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
        If keyData = Keys.Escape Then
             Console.WriteLine("Yeha Esc pushed..")
             Return True
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
   End Function







当我需要检测在我的应用程序外部按下的键时,我在VB6中使用了 GetAsyncKeyState 。但不幸的是,你需要一个额外的线程或计时器,因为你总是需要检查你的按键是否被按下。不知道现在是否有更好的方法,过去几年从未需要这些功能... ^^

(我猜4肯定有,但我不知道他们)



这是一个小例子




Back then in VB6 I used GetAsyncKeyState when I needed to detect Keys pressed outside my App. But unfortunately you need an extra Thread or an Timer for that, as you allways need to check if your Keys are pressed. Don't know if there are better ways now, never needed that functionality in the last years... ^^
(I guess 4 sure there are, but I don't know em)

Here is a litte example

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As IntPtr) As IntPtr
Private Sub Timer_Or_Thread_WhateverRoutine
    Dim result As IntPtr = GetAsyncKeyState(New IntPtr(Keys.F5))
    If result.ToInt32 < 0 Then
        MessageBox.Show("F5 Pushed")
    End If
End Sub


这篇关于VB.NET表单操作作为系统托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆