在KeyPress事件中添加如下
private void bbb_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==13)//判断如果是回车
{
aaa.Focus();//aaa控件获得输入焦点
}
}
记得接贴,我现在穷,否则鄙视你。见你贴不回
private void bbb_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==13)//判断如果是回车
{
aaa.Focus();//aaa控件获得输入焦点
}
}
记得接贴,我现在穷,否则鄙视你。见你贴不回
public delegate void TextBoxEnterPressedHandler(string text);
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private void InitializeComponent()
{
//...
this.textBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyUp);
//...
} public event TextBoxEnterPressedHandler TextBoxEnterPressed; private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode==Keys.Enter && TextBoxEnterPressed!=null )
TextBoxEnterPressed( textBox1.Text );
} public void SetFocus()
{
this.textBox1.Focus();
}
}
public class Form1 : System.Windows.Forms.Form
{
private WindowsControlLibrary1.UserControl1 aaa;
private WindowsControlLibrary1.UserControl1 bbb;
public Form1()
{
aaa.TextBoxEnterPressed += new WindowsControlLibrary1.TextBoxEnterPressedHandler(aaa_TextBoxEnterPressed);
bbb.TextBoxEnterPressed += new WindowsControlLibrary1.TextBoxEnterPressedHandler(bbb_TextBoxEnterPressed);
}private void aaa_TextBoxEnterPressed(string text)
{
bbb.SetFocus();
} private void bbb_TextBoxEnterPressed(string text)
{
aaa.SetFocus();
}
}