1. VBnet做的程序,如何让用户修改快捷键
建议你这样试试看:
当按下按钮时,获取下拉框的按键名称,再将字符串转换Keys枚举,然后进行判断
2. VB中如何设置热键和快捷键
希望某一字符成为访问键,也可以在该字符前面加上一个 (&) 字符。
可以通过在 Caption 属性设置中使用 & 字符来为命令、菜单、和控件指定访问键。
要对菜单项赋值快捷键,请按照以下步骤执行:
1.打开“菜单编辑器”。
2.选取该菜单项。
3.在“快捷键”组合框中选取功能键或者键的组合。
要删除快捷键赋值,应选取列表顶部的"(none)"。
3. vb快捷键怎么改
类似Alt+右、F11这种快捷键是无法更改的,但是类似(&W)这种快捷键是可以更改的。你有没有注意到自动完成关键字可以用两种快捷键实现?一种是Alt+右,一种是分别按下右键快捷菜单键(右边的Windows键和Ctrl之间)和W。
所以我们可以更改后者。方法是:菜单视图 工具栏 自定义 单击工具栏选项卡 勾选快捷菜单 在出来的菜单里面点代码窗口 代码窗口 右击自动完成关键字 更改它的名称,比方说把(&W)改成(&E),那么以后就可以通过右键快捷菜单键+E来实现了
4. vb 按钮快捷键怎么设置
设置VB窗体中按扭快捷键的操作可以采用下面两种方法来实现:
1、在按扭的Capion
属性设置标题的时候,前面增加
"&K"字符就可以,K代表的是你准备使用的Alt+键盘字符,如“&O.退出”,程序运行的时候按下
Alt+O
即执行该按扭的操作了
2、你可以利用该按扭所在的Form
窗体优先权获得键盘操作功能来激发你要完成的按扭操作,此时首先要设置Form
的KeyPreview
属性值为
True,然后在
Form中KeyDown事件中判断你需要的组合键盘值来激发你的按扭事件.
Form_KeyDown事件中的各功能键值组合比较全面,如Shift,Alt
及Ctr等,一般都能满足快捷键的组合需求了.
Exp:
利用Ctrl+O组合键激发上面所说的按扭键,在Form_KeyDown事件中添加如下代码
Private
Sub
Form_KeyDown(KeyCode
As
Integer,
Shift
As
Integer)
If
Shift
=
2
And
KeyCode
=
79
Then
btnQuit_Click()
End
If
End
Sub
btnQuit_Click()是退出程序按扭事件
5. VB中如何为程序设置快捷键
用全局热键
运行后程序自动隐藏,按快捷键自动出现
'第一步:
'新建一个窗口,将以下代码复制进去
注册热键为:'Ctrl+Alt+P
Private
Sub
Form_Load()
form1.hide
Dim
ret
As
Long
preWinProc
=
GetWindowLong(Me.hwnd,
GWL_WNDPROC)
ret
=
SetWindowLong(Me.hwnd,
GWL_WNDPROC,
AddressOf
Wndproc)
idHotKey
=
1
Modifiers
=
MOD_Alt
+
MOD_Ctrl
uVirtKey
=
vbKeyP
ret
=
RegisterHotKey(Me.hwnd,
idHotKey,
Modifiers,
uVirtKey)
End
Sub
Private
Sub
Form_Unload(Cancel
As
Integer)
Dim
ret
As
Long
ret
=
SetWindowLong(Me.hwnd,
GWL_WNDPROC,
preWinProc)
Call
UnregisterHotKey(Me.hwnd,
uVirtKey)
End
Sub
'第二步
'新建立一个模块,然后将以下内容复制到模块中
Option
Explicit
Declare
Function
SetWindowLong
Lib
"User32"
Alias
"SetWindowLongA"
(ByVal
hwnd
As
Long,
ByVal
nIndex
As
Long,
ByVal
dwNewLong
As
Long)
As
Long
Declare
Function
GetWindowLong
Lib
"User32"
Alias
"GetWindowLongA"
(ByVal
hwnd
As
Long,
ByVal
nIndex
As
Long)
As
Long
Declare
Function
CallWindowProc
Lib
"User32"
Alias
"CallWindowProcA"
(ByVal
lpPrevWndFunc
As
Long,
ByVal
hwnd
As
Long,
ByVal
Msg
As
Long,
ByVal
wParam
As
Long,
ByVal
lParam
As
Long)
As
Long
Declare
Function
RegisterHotKey
Lib
"User32"
(ByVal
hwnd
As
Long,
ByVal
id
As
Long,
ByVal
fsModifiers
As
Long,
ByVal
vk
As
Long)
As
Long
Declare
Function
UnregisterHotKey
Lib
"User32"
(ByVal
hwnd
As
Long,
ByVal
id
As
Long)
As
Long
Public
Const
WM_HOTKEY
=
&H312
Public
Const
MOD_Alt
=
&H1
Public
Const
MOD_Ctrl
=
&H2
Public
Const
MOD_Shift
=
&H4
Public
Const
GWL_WNDPROC
=
(-4)
Public
preWinProc
As
Long
Public
Modifiers
As
Long,
uVirtKey
As
Long,
idHotKey
As
Long
Private
Type
taLong
ll
As
Long
End
Type
Private
Type
t2Int
lWord
As
Integer
hWord
As
Integer
End
Type
Public
Function
Wndproc(ByVal
hwnd
As
Long,
ByVal
Msg
As
Long,
ByVal
wParam
As
Long,
ByVal
lParam
As
Long)
As
Long
If
Msg
=
WM_HOTKEY
Then
If
wParam
=
idHotKey
Then
Dim
lp
As
taLong,
i2
As
t2Int
lp.ll
=
lParam
LSet
i2
=
lp
If
(i2.lWord
=
Modifiers)
And
i2.hWord
=
uVirtKey
Then
form1.show
End
If
End
If
End
If
Wndproc
=
CallWindowProc(preWinProc,
hwnd,
Msg,
wParam,
lParam)
End
Function