日期:2014-05-19  浏览次数:20813 次

请问如何判断这种情况
在一个窗体中有两个TextBox(TextBox1和TextBox2),我要在按下快捷健F1的时候向两个TextBox中输入数据,初始焦点在TextBox1,用的是这种方式:
SendKeys.Send("abc");
SendKeys.Send( "{TAB} ");
SendKeys.Send("def");
当不改变数据焦点的时候,能完成正常的功能,可是当在按下F1之前把光标移到了TextBox2后整个数据的数据就反了,我想让在按下F1之前就算点了TextBox2也能正常的输入想要的数据,请问要怎么做啊?
请各位高手指点一下
环境是Winform,.net2003

------解决方案--------------------
this.TextBox1.Focus();
SendKeys.Send("abc");
SendKeys.Send( "{TAB} ");
SendKeys.Send("def");

------解决方案--------------------
this.textBox1.Focus();
SendKeys.Send("abc");
this.textBox2.Focus();
SendKeys.Send("def");

还有,你直接设置Text属性不行吗,为什么要SendKeys啊
------解决方案--------------------
建议使用用户控件

------解决方案--------------------
1.定好规矩
2.循环form内的controls判断是否是合适的控件,如果是control.Text = "规定的值 "
------解决方案--------------------
void button1_Click(object sender, EventArgs e)
{
string[] val ={ "abc ", "def ", "ghi " };
int i = 0;
while (true)
{
foreach (Control c in this.Controls)
{
if (c.GetType().Name.Equals( "TextBox ") && c.TabIndex == i)
{
c.Text = val[i];
i++;
}
if (i == val.Length)
{
return;
}
}
}
}