[CODE]using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(80, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(96, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
this.textBox1 .KeyDown +=new KeyEventHandler(textBox1_KeyDown);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(72, 112);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "textBox2";
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
this.textBox2 .KeyDown +=new KeyEventHandler(textBox2_KeyDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
this.textBox2.Focus();
}
}
private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
this.textBox1.Focus();
}
}
}
}
[/CODE]
以上是form里的程序
是按照2楼的内容运行的
同时支持TAB和ENTER
运行系统 WIN2003 SERVER 运行环境 .NET2003
[此贴子已经被作者于2006-6-28 15:27:47编辑过]
<SCRIPT language=javascript>
function setfocus() { document.all.t2.focus(); }
</script>
[此贴子已经被作者于2006-6-29 11:30:16编辑过]