如何输入键盘光标移动到VB.NET中的其他文本框 [英] How to enter key board cursor move to other textbox in VB.NET

查看:285
本文介绍了如何输入键盘光标移动到VB.NET中的其他文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,所有访客.
我在Access上创建了一个表单,然后在该表单上放置了一些文本框,当我运行该表单时,可以按 Enter Keyboard 键,光标将与其他文本框一起放置.
但是在VB.NET中,当我按输入键盘时,光标仍然与旧的文本框放置在一起

任何人都知道vb.net如何按下输入键盘并将光标放在其他文本框(如Access)上?

此致

Hi all visitors.
I have created one form on Access and on that form i drop some textboxes and when i run that form, i can press Enter Keyboard and the cursor will place with other textbox.
But in VB.NET,When i press Enter Keyboard the cursor still place with the old textbox

Anyone know how vb.net can press Enter keyboard and place cursor on other textbox like Access?

Best Regards,

推荐答案

您在文本框按键事件中编写代码:-
you write code in in textbox keypress event:-
if(e.keychar==13)
{
//write code for focus next code
}


请注意:您所描述的是预期的行为,因此修改此行为可能会造成一些混乱.

根据当前键盘focus显示文本框光标.同时,这可能是有道理的.要检测Enter,请在需要传递键盘焦点的每个控件上处理事件KeyDown.事件处理程序应使用Control.Focus集中控制下一个控件.
我没有提供确切的MSDN链接和完全限定的类型名称,因为您没有标记要使用的UI库.我的建议适用于WPF ControlSystem.Windows.Form.ControlTextBox,但是名称空间不同.

您应该喜欢以下模式:为所有此类控件和焦点转换表创建一个事件处理程序.您可以找出哪个控件从参数object sender中获取了Enter键,并将其传递给事件处理程序.过渡表应从当前集中的控件中定义下一个控件.

—SA
Be careful: what you describe is expected behavior, so modification of this behavior can make some confusions.

Text box cursor is shown according to current keyboard focus. At the same time, it may make sense. To detect Enter, handle the event KeyDown on each control you need to pass keyboard focus. The event handler should focus the next control using Control.Focus.

I do not provide exact MSDN links and fully qualified type names because you not tag the UI library you want to use. My advice works for WPF Control and System.Windows.Form.Control and TextBox, but the name spaces are different.

You should prefer the following schema: create one single event handler of all such control and the table of focus transitions. You can find out which control got the key Enter from the parameter object sender, passed to the event handler. The transition table should define next control from the currently focused control.

—SA


在textBox按键事件上使用此功能
这里txtUID和txtPassword是两个文本框.这里要检查txtUID是否为空或说是否已填充,然后按Enter键,焦点将移至txtPassword
use this on textBox Keypress Event
here txtUID and txtPassword are two textBoxes .here it is checking if txtUID is not blank or say if it is Filled and then Pressing Enter the Focus Will move to txtPassword
Private Sub txtUID_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUID.KeyPress
            If Asc(e.KeyChar) = Keys.Enter Then
                If txtUID.Text.Trim() <> "" Then
                    txtPassword.Focus()
                End If
            End If
        End Sub


根据您的需要实施.


Implement this as Per your need.


这篇关于如何输入键盘光标移动到VB.NET中的其他文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆