C#:ComboBox Enter to Tab [英] C#: ComboBox Enter to Tab

查看:88
本文介绍了C#:ComboBox Enter to Tab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个带有添加项目的组合框,一旦按下comboBox中的enter,它应该转到下一个标签索引。我使用下面的代码用于textBox并且它正常工作,但是对于comboBox不工作,请指教。



Hi,

I have a combobox with added items, once I press the enter in the comboBox, it should go to the next tab index. I have using below code for the textBox and it's working, but for the comboBox not working, please advise.

private void textBox9_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)Keys.Enter)
    {
        SendKeys.Send("{TAB}");
    }
}

推荐答案

使用 SendKeys 的UI开发是一件很脏的事情。所有你真的需要它来阅读适当的关注帮助。请参阅:

http:// msdn .microsoft.com / zh-cn / library / system.windows.forms.control.getnextcontrol.aspx [ ^ ]。



此外,请注意修改表格和控件的默认行为。







如果可以是这样的:
Using SendKeys of UI development is a dirty thing. All you really need it to read help with proper attention. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.getnextcontrol.aspx[^].

Besides, be careful with modification of default behavior of forms and controls.



If can be something like:
Panel parent = //... // parent panel, form.., the parent of the controls to be focused
Form form = //... // the form containing controls in question

//...

// focus forward:
Control next = parent.GetNextControl(form.ActiveControl, true);
next.Focus();





-SA


尝试使用这个

try using this
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                textBox1.Focus();//your control to focus
            }
        }






我尝试了同样的方法,它也适用于组合框。请检查是否有任何其他事件阻止此事件发生。
Hi,

I tried the same and it works fine with combo box also. Please check if there is any other event which stops this event from raising.


这篇关于C#:ComboBox Enter to Tab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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