![VB.NET VB.NET](http://www.spersky.com/logo/VB.NET.gif)
ASP/Visual Basic Code复制内容到剪贴板
- Const MYKEYID1 As Integer = 9
- Const MYKEYID2 As Integer = 10
- Public Const MOD_ALT As Integer = &H1 'Alt key
- 'Public Const VK_NUMPAD1 As Integer = &H61 'NumPad 1 key
- 'Public Const VK_NUMPAD2 As Integer = &H62 'NumPad 2 key
- Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
- Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
- Public Const WM_HOTKEY As Integer = &H312
- Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
- If m.Msg = WM_HOTKEY And m.WParam.ToInt32 = MYKEYID1 Then
- 'Me.Text = DateTime.Now.Second.ToString & "key 1"
- Me.WindowState = FormWindowState.Normal
- ElseIf m.Msg = WM_HOTKEY And m.WParam.ToInt32 = MYKEYID2 Then
- 'Me.Text = DateTime.Now.Second.ToString & "key 2"
- 'Me.WindowState = FormWindowState.Minimized
- If Me.WindowState = FormWindowState.Normal Then
- Me.WindowState = FormWindowState.Minimized
- 'Me.ShowInTaskbar = False
- Hide()
- Else
- If rbt2.Checked = False Then
- gbBiji.Visible = False
- 'gbShoucang.Visible = True
- Else
- 'gbShoucang.Visible = False
- gbBiji.Visible = True
- End If
- Show()
- Me.WindowState = FormWindowState.Normal
- Me.ShowInTaskbar = True
- End If
- End If
- MyBase.WndProc(m) 'Never Forget This
- End Sub
- Private Sub frmTXL_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- WindowState = FormWindowState.Minimized
- Visible = False
- ' Me.ShowInTaskbar = False
- If My.Settings.trayClose = True Then
- e.Cancel = True '不关闭
- Else
- UnregisterHotKey(Me.Handle, MYKEYID1) 'Remember to unregister the hotkey
- UnregisterHotKey(Me.Handle, MYKEYID2) 'Remember to unregister the hotkey
- End
- End If
- '' Exit Sub
- End Sub '记录选择过的分组
此外还要在load事件中添加如下代码
ASP/Visual Basic Code复制内容到剪贴板
- RegisterHotKey(Me.Handle, MYKEYID1, MOD_ALT, CInt(Keys.D1)) '最后一个参数可变
- RegisterHotKey(Me.Handle, MYKEYID2, MOD_ALT, CInt(Keys.D2))
更多参考:msdn