vs2010 C# winform textbox 回车后 跳转到下一个
代码如图,按回车不报错也没反应,什么原因?
private void xingming_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
xingbie.Focus();
}
}
你确认绑定xingming_KeyDown事件了吗,如果绑定了,在第一句打上断点,看看进入没有
在构造函数加上 xingming.KeyDown += xingming_KeyDown;
不好意思,我是外行,自己瞎捅咕,请问哪里是构造函数?如何确认是否绑定?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace simshow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//webBrowser1.Document.body.scroll = "yes";
webBrowser1.Navigate("https://cbss.10010.com/essframe");
}
private void button1_Click(object sender, EventArgs e)
{
//webBrowser1.Document.All[""].SetAttribute("value", "你的帐号");
HtmlElement HE_yonghuming = webBrowser1.Document.All["STAFF_ID"]; //帐号文本框的名字
HE_yonghuming.SetAttribute("value", yonghuming.Text);
HtmlElement HE_LOGIN_PASSWORD = webBrowser1.Document.All["LOGIN_PASSWORD"]; //帐号文本框的名字
HE_LOGIN_PASSWORD.SetAttribute("value", mima.Text);
HtmlElement HE_LOGIN_PROVINCE_CODE = webBrowser1.Document.All["LOGIN_PROVINCE_CODE"]; //帐号文本框的名字
HE_LOGIN_PROVINCE_CODE.SetAttribute("value", "90");
}
private void xingming_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
xingbie.Focus();
}
}
}
}
怎么绑定呢?在设计器里怎么操作?
关键是keyvalue值不是ASCII值吧。回车不是13
因为该文件的designer.cs文件没有添加“键盘输入”这个触发事件的设置。需要添加这段代码:t this.xingming.KeyDown += new System.Windows.Forms.KeyEventHandler(this.xingming_KeyDown);