新建一个Form1把Form1的KeyPreview改成True
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:做网站、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的托克托网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
拖入一个Button1到Form1上面
然后加入以下代码
Private
Sub
Form1_KeyDown(sender
As
Object,
e
As
KeyEventArgs)
Handles
Me.KeyDown
If
e.KeyData
=
(Keys.Alt
Or
Keys.G)
Then
Button1.PerformClick()
'或者用Button1_Click(Nothing,
New
EventArgs)
'快捷键Alt+G触发Button1_Click()事件。
End
If
End
Sub
Private
Sub
Button1_Click(sender
As
Object,
e
As
EventArgs)
Handles
Button1.Click
Button1.Size
=
New
Size(180,
23)
Button1.Text
=
"我被局部快捷键给召唤了~"
End
Sub
新建窗口,添加picture控件
利用line()方法画线
line(开始x坐标,开始y坐标)-(结束x坐标,结束y坐标),线的颜色,画线的方式(默认为线,B为矩形无填充,BF为填充的矩形)
For i = 1 To 16
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(255, 0, 0)
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(255, 0, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(0, 255, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(0, 255, 0)
Next i
如果要在窗口上画也可以调用窗口的line方法即form.line()
选到TextBox1的keydown方法,然后val=keycode不行么?
焦点在哪个控件,哪个控件就会有keydown,没有焦点也就不会有。
1. F12:转到定义;Shift+F12:转到引用
2. F5:启动;Ctrl+F5:开始执行(不调试);Shift+F5:停止调试
3. F7:查看代码;Shift+F7:查看视图设计器
4. Ctrl+Alt+L:解决方案资源管理器
5. Ctrl+Alt+J:对象浏览器
6. F4:显示属性窗口
7. Ctrl+Alt+X:工具箱
8. Ctrl+Alt+C类视图
9. Alt+Enter:查看属性
10.F10:逐过程调试
11.F11:逐语句调试
12.Ctrl+B:新断点
13.Ctrl+Shift+F9:清除所有断点
14.Ctrl+Shift+B生成解决方案
15.Shift+Alt+Enter:全屏
16.大纲显示:Ctrl+M, Ctrl+M:切换大纲显示展开;Ctrl+M, Ctrl+L:切换所有大纲显示;Ctrl+M,Crtl+P停止大纲显示;Ctrl+M, Ctrl+O:折叠到定义
17.智能感知:Ctrl+J:列出成员;Ctrl+Shift+空格:参数信息; Ctrl+K,Ctrl+I:快速信息;Alt+右箭头键:完成单词
见下面的代码
Public Class Form1
Public Declare Auto Function RegisterHotKey Lib "user32.dll" Alias "RegisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
Public Declare Auto Function UnRegisterHotKey Lib "user32.dll" Alias "UnregisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'注册全局热键
RegisterHotKey(Handle, 0, 0, Keys.F4)
'第3个参数意义: 0=nothing 1 -alt 2-ctrl 3-ctrl+alt 4-shift 5-alt+shift 6-ctrl+shift 7-ctrl+shift+alt
End Sub
Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
UnRegisterHotKey(Handle, 0)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = 786 Then
Me.Activate()
End If
MyBase.WndProc(m)
End Sub
End Class