组合框按键事件问题 [英] combobox keypress event problem
本文介绍了组合框按键事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
当我从组合框中选择项目然后按回车键时,我无法进入textbox1,当我按下回车键时我想专注于textbox1组合框。
以下是我的代码..
Private Sub combobox1_KeyPress( ByVal sender As Object,ByVal e As System.Windows.Forms.KeyPressEventArgs)Handles ComboBox1.KeyPress
If Asc(e.KeyChar)= 13 Then
e.Handled = True
TextBox1.Focus ()
退出Sub
结束如果
结束子
[已编辑]代码包含在pre标签[/ edited]
解决方案
我使用了相同的代码,然后在从Combobox1选择值后按Enter键检查是否有效。它对我有用,它按下后输入成功聚焦TextBox1。当我改变TextBox时它的焦点对应Textbox。所以我在这个编码中没有收到任何错误。
使用按键事件。
private void comboBox1_KeyDown( object sender,KeyEventArgs e)
{
if (e.KeyValue == 13 )
{
textBox1.Focus();
}
}
在VB中
私有 Sub combobox1_KeyDown( ByVal 发件人作为 对象, ByVal e As System.Windows.Forms.KeyEventArgs)句柄 ComboBox1.KeyDown
< span class =code-keyword>如果 e.keyValue = 13 那么
textBox1.Focus();
结束 如果
结束 Sub
看看我再次检查了你的ComboBox1_KeyPress
给出的事件编码
正如您在评论中提到的那样,您在Form_Load事件中的ComboBox
中添加了一些值。我还写了一个能够在FormLoad事件中填写
ComboBox
的函数
私有 Sub ADDData( ByVal cmb As ComboBox)
Dim i 作为 整数
对于 i = 0 10
cmb.Items.Add(i )' 在相应的组合框中添加1到10的值
下一步
结束 Sub
私人 Sub Form1_Load( ByVal sender As System。对象, ByVal e As System.EventArgs)句柄 MyBase .Load
ADDData(ComboBox1)' form_load事件中的调用方法,用于添加值im Combobox
结束 Sub
私人 Sub ComboBox1_KeyPress( ByVal sender As System 。对象, ByVal e 作为系统。 Windows.Forms.KeyPressEventArgs)句柄 ComboBox1.KeyPress
如果 Asc(e.KeyChar)= 13 然后
e.Handled = True
TextBox1.Focus( )' 选择值后,它会关注TextBox1并按下
退出 Sub
结束 如果
结束 Sub
Hi all,
When I select item from combobox and then press enter, I cant go in textbox1, I want to focus on textbox1 when I press enter in combobox.
following is my code..
Private Sub combobox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress If Asc(e.KeyChar) = 13 Then e.Handled = True TextBox1.Focus() Exit Sub End If End Sub
[Edited]Code is wrapped in "pre" tags[/Edited]
解决方案
I've used same code and then press Enter after selecting value from Combobox1 to check its works or not. its works for me it successfully focusing TextBox1 after press enter. when I changed TextBox its focus corresponding Textbox. So I didn't get any error in this Coding.
Use the key down event.
private void comboBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { textBox1.Focus(); } }
In VB
Private Sub combobox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown If e.keyValue=13 Then textBox1.Focus(); End If End Sub
Take a look I've again checked yourComboBox1_KeyPress
Event Coding as given
as You mentioned in Comment you are adding Some value inComboBox
in Form_Load event. I've also write a function which will able to fillComboBox
inFormLoad event
Private Sub ADDData(ByVal cmb As ComboBox) Dim i As Integer For i = 0 To 10 cmb.Items.Add(i) ' Add value from 1 to 10 in corresponding combobox Next End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ADDData(ComboBox1) 'Calling method in form_load event for adding value im Combobox End Sub
Private Sub ComboBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress If Asc(e.KeyChar) = 13 Then e.Handled = True TextBox1.Focus() 'it focus on TextBox1 after selecting value and press enter Exit Sub End If End Sub
这篇关于组合框按键事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文