| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3016 人关注过本帖
标题:如何用回车键直接转到下一个文本框
只看楼主 加入收藏
lxlijun001
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-6-28
收藏
 问题点数:0 回复次数:15 
如何用回车键直接转到下一个文本框
在C#.NET中,如何不使用TAB键,而直接用回车键将光标转到下一个文本框,谢谢
搜索更多相关主题的帖子: 文本框 回车键 TAB 光标 NET 
2006-06-28 08:49
shanshao
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-5-20
收藏
得分:0 
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
this.textBox2.Focus();
}
}
2006-06-28 10:57
lxlijun001
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-6-28
收藏
得分:0 

你好,我的版本是2003,用不了,在textBox2的属性里根本就没有Focus(),谢谢能不能再写一段

2006-06-28 13:49
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 

[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编辑过]


此号自封于2006年11月30日
2006-06-28 15:23
lxlijun001
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-6-28
收藏
得分:0 

不是Windows应用程序,而是Web应用程序

2006-06-28 15:31
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
以下是引用lxlijun001在2006-6-28 15:31:56的发言:

不是Windows应用程序,而是Web应用程序

俺也不知道了 等待答案


此号自封于2006年11月30日
2006-06-28 16:58
zklwzh
Rank: 2
等 级:论坛游民
帖 子:275
专家分:25
注 册:2005-11-16
收藏
得分:0 
这个要用JAVASCRIPT来实现。具体的语句我也不太清楚,你可到JAVASCRIPT论谈去看一下。

2006-06-28 17:47
foproxs
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2006-4-24
收藏
得分:0 
以下是引用noshow在2006-6-28 16:58:44的发言:

俺也不知道了 等待答案

document.all.textbox1.focus();


2006-06-28 19:27
lxlijun001
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-6-28
收藏
得分:0 
上面的都不行,还有吗?谢谢!!!!
在Web应用程序中如何设置文本框的焦点
2006-06-29 10:04
marer
Rank: 2
等 级:新手上路
威 望:3
帖 子:928
专家分:0
注 册:2005-7-18
收藏
得分:0 
给你一个示例吧:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="回车使下一个文本框得到焦点.WebForm1" %>
程序代码:
<SCRIPT language=javascript>
function setfocus() { document.all.t2.focus(); }
</script>

[此贴子已经被作者于2006-6-29 11:30:16编辑过]


public class 人生历程 extends Thread{public void run(){while(true){努力,努力,再努力!!;Thread.sleep(0);}}}
2006-06-29 11:29
快速回复:如何用回车键直接转到下一个文本框
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012498 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved