以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  方向键切换所在控件光标  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=114396)

--  作者:281512373
--  发布时间:2018/2/5 13:37:00
--  方向键切换所在控件光标

图片点击可在新窗口打开查看此主题相关图片如下:qq截图20180205133456.png
图片点击可在新窗口打开查看



5列
10行

方向键切换所在控件光标   上下左右
[此贴子已经被作者于2018/2/5 14:09:37编辑过]

--  作者:有点甜
--  发布时间:2018/2/5 14:33:00
--  

1、你文本框的命名必须规则,比如 txt_1_1  txt_2_3  如 txt_横向位置_纵向位置

 

2、编写keydown事件,写代码,如

 

If e.keycode = keys.down Then

    dim x = e.sender.name.split("_")(1)

    dim y = e.sender.name.split("_")(2)

    e.form.controls("txt_" & x & "_" & y+1).select  \'横坐标不变,纵坐标加1

    e.cancel = true

End If

[此贴子已经被作者于2018/2/5 14:33:42编辑过]

--  作者:281512373
--  发布时间:2018/2/5 15:13:00
--  
我命名是h1,h2,h3 一直到h50 程序很多了 不好重新命名  左右是错的

If Typeof e.Sender Is  WinForm.TextBox Then
    
    Dim Index As Integer = CInt(e.Sender.Name.Replace("h",""))
    Select Case e.KeyCode
        Case keys.Down
            e.Cancel = True
            If Index <> 10 AndAlso Index <> 20 AndAlso Index <> 30 AndAlso Index <> 40 AndAlso Index <> 50 Then e.Form.Controls("h" & (Index+1)).Select
        Case keys.Left
            e.Cancel = True
            If Index > 10 Then e.Form.Controls("h" & (Index-10)).Select
        Case keys.Right
            e.Cancel = True
            If Index <= 40 Then e.Form.Controls("h" & (Index+10)).Select
        Case keys.Up
            e.Cancel = True
            If Index <> 1 AndAlso Index <> 11 AndAlso Index <> 21 AndAlso Index <> 31 AndAlso Index <> 41 Then e.Form.Controls("h" & (Index-1)).Select
    End Select
End If

--  作者:有点甜
--  发布时间:2018/2/5 15:33:00
--  

左右代码没问题,你加入msgbox,弹出计算后的值是否正确。

 

我单独测试没问题,可以正常切换。


--  作者:281512373
--  发布时间:2018/2/5 15:58:00
--  
左右好像跟 tab 键冲突了
--  作者:有点甜
--  发布时间:2018/2/5 16:02:00
--  
以下是引用281512373在2018/2/5 15:58:00的发言:
左右好像跟 tab 键冲突了

 

实例发上来测试。