设置以下 Default属性: 为TRUE 回车键直接触发
keybd_event
'模块
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const KEYEVENTF_KEYUP = &H2
'窗体
Private Sub Timer1_Timer()
Call keybd_event(13, 0, 0, 0) vb开始按钮代码
Call keybd_event(13, 0, KEYEVENTF_KEYUP, 0)
End Sub
'模块
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const KEYEVENTF_KEYUP = &H2
'窗体
Private Sub Timer1_Timer()
Call keybd_event(13, 0, 0, 0) vb开始按钮代码
Call keybd_event(13, 0, KEYEVENTF_KEYUP, 0)
End Sub
就是我说的这样喽。
Enter的Ascii是13,timer的时间控制间隔长短
准确的方法是FindWindow来寻窗体,这个肯定是子窗体了。
可能要用FindWindowEx,然后到的话在SendMessage WM_KeyDown
VK_Enter到到的HWND。
如果不需要太准确。直接模拟键盘
Call keybd_event(13, 0, 0, 0)
Call keybd_event(13, 0, KEYEVENTF_KEYUP, 0)
Private Sub Timer1_Timer()
DoEvents
SendKeys "{enter}"
End Sub
DoEvents
SendKeys "{enter}"
End Sub
前提是设好了每个空件的TabIndex
if KeyAscii=13 then
SendKeys "{Tab}"
end ifTop
if KeyAscii=13 then
SendKeys "{Tab}"
end ifTop
2 楼chenyu5188(来自东方的狼)回复于 2003-03-05 10:02:04 得分 0
用sendkeys函数。
楼上有示例代码。Top
楼上有示例代码。Top
3 楼Cooly(☆不做开发很久了......☆)回复于 2003-03-05 10:03:18 得分 0
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 13
'回车
Case 37
Select Case KeyCode
Case 13
'回车
Case 37
'左方向键
Case 38
'上方向键
Case 39
'右方向键
Case 40
'下方向键
End Select
End Sub
Top
Case 38
'上方向键
Case 39
'右方向键
Case 40
'下方向键
End Select
End Sub
Top
4 楼Leftie(左手,为人民币服务)回复于 2003-03-05 10:46:35 得分 0
Private Sub text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Or KeyCode = vbKeyDown Then text2.SetFocus
If KeyCode = vbKeyReturn Or KeyCode = vbKeyDown Then text2.SetFocus
End Sub
Private Sub text2_KeyDown(KeyCode As Integer, Shift As Integer)
if keycode=vbkeyup then text1.setfocus
If KeyCode = vbKeyReturn Or KeyCode = vbKeyDown Then text3.SetFocus
End Sub
...
...
Private Sub text2_KeyDown(KeyCode As Integer, Shift As Integer)
if keycode=vbkeyup then text1.setfocus
If KeyCode = vbKeyReturn Or KeyCode = vbKeyDown Then text3.SetFocus
End Sub
...
...
如上
______________________________________________________________________________________________
答1:
我的页面上有几个button,现在回车键要触发某个button 事件.如何设置???
______________________________________________________________________________________________
答2:
用asp的web控件,把按钮放在form中就行了,系统会自动在你回车时触发onclick事件
<form runat="server">
<asp:button id="button1" runat="server" onclick="button1_click"/>
</form>
______________________________________________________________________________________________
答3:
老大,我有好几个button,要触发的是其中的某个特定的button 的事件.
______________________________________________________________________________________________
答4:
应该有个tabindex类是的属性,你一下
______________________________________________________________________________________________
答5:
tableindex,但也不完全是。往窗体上放button时,注意顺序,回车触发的按钮先放。
______________________________________________________________________________________________
答6:
tableindex这个属性不行啊,而顺序?这不是回车肯定要触发一个button了吗?这好象有点勉强了把.如果我要求回车键哪个button都不触发的话又怎么办呢
______________________________________________________________________________________________
答7:
OnKeyDown="if (event.keyCode==13)document.all.要激活的按钮id.click()"
______________________________________________________________________________________________
答8:
可以把OnKeyDown加在<form runat="server">中
______________________________________________________________________________________________
答9:
to:ahui_net(阿灰)
好象也不对啊,我的button控件是服务器端的,先要取得客户端id.
这也不是解决的好办法.如果我的button已经响应了onclik事件,现在我想不让他响应呢?
我想应该是在属性设置上的问题,而不是代码编写上的问题.
______________________________________________________________________________________________
答10:
关注
______________________________________________________________________________________________
答11:
在你的代码中加上这段:假设你的form的id为myform,button的id为mybutton
string ref=Page.GetPostBackEventReference(mybutton);
myform.Attributes.Add("onkeydown","if(event.keyCode==13){if(PageValidate(){"+ref+";}}");
绝对原创!
______________________________________________________________________________________________
答12:
老大,还是不行
在cs文件里myform不包含对Attributes的定义
______________________________________________________________________________________________
答13:
你有没有在CS文件里声明你的HtmlForm,象这样:
protected HtmlForm myform;
______________________________________________________________________________________________
答14:
如果是LinkButton怎么解决?
______________________________________________________________________________________________
答15:
LintButton一样。
在vb中实现窗体上回车键代替TAB键,用如下方法:
首先设置窗体的 KeyPreview 属性为true
然后加入以下代码:
Private Sub FrmLogin_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
'用回车代替Tab
If e.KeyChar = Chr(13) Then
e.Handled = True
SendKeys.Send("{TAB}")
End If
End Sub
首先设置窗体的 KeyPreview 属性为true
然后加入以下代码:
Private Sub FrmLogin_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
'用回车代替Tab
If e.KeyChar = Chr(13) Then
e.Handled = True
SendKeys.Send("{TAB}")
End If
End Sub
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论