textbox相关问题

NT5763 2010-10-12 10:57:21

textbox1输入满格后自动到textbox2,类推
按tab时从textbox1到textbox4
...全文
142 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
w5588660 2010-10-13
  • 打赏
  • 举报
回复
textbox的事件可以改!
fangxiaofelix 2010-10-13
  • 打赏
  • 举报
回复
1楼、2楼已有正解!
LZ要学会举一反三!
NT5763 2010-10-13
  • 打赏
  • 举报
回复
那删除时退格呢
fysy0000 2010-10-12
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Ques_1
{
public partial class Form1 : Form
{
private const int textSize = 5;//设置你每个textbox输入上限
public Form1()
{
InitializeComponent();
}
//这样写不能保证像激活码那样在第一个复制进去全部刚好,要一个个的textbox输入,要是要那种的话,可以采用下面的另一种方式
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.MaxLength = textSize;
this.textBox2.MaxLength = textSize;
this.textBox3.MaxLength = textSize;
this.textBox4.MaxLength = textSize;
this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
this.textBox2.TextChanged += new EventHandler(textBox2_TextChanged);
this.textBox3.TextChanged += new EventHandler(textBox3_TextChanged);
this.textBox4.TextChanged += new EventHandler(textBox4_TextChanged);
}

void textBox4_TextChanged(object sender, EventArgs e)
{

}

void textBox3_TextChanged(object sender, EventArgs e)
{
if (textBox3.Text.Length >= textSize)
{
this.textBox4.Focus();
}
}

void textBox2_TextChanged(object sender, EventArgs e)
{

if (textBox2.Text.Length >= textSize)
{
this.textBox3.Focus();
}
}

void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Length >= textSize)
{
this.textBox2.Focus();
}
}
}
}
tx066415 2010-10-12
  • 打赏
  • 举报
回复
这就要看你输入多少字符了 你根据字符长度来判断 如果输入满了 就调用 下一个的Textbox的焦点方法啊
  • 打赏
  • 举报
回复
应该很简单的啊? 判断长度满足有 光标移到下一个textbox控件中。。。
wuyq11 2010-10-12
  • 打赏
  • 举报
回复
设置 tabindex

private void textBox_TextChanged(object sender, EventArgs e)
{
TextBox txt=sender as TextBox;
if (txt.Text.Length >= 6)
{
this.Controls[""].Focus();
}
}
this.ActiveControl = textBox2;
SendKeys.Send("{TAB}");


ZengHD 2010-10-12
  • 打赏
  • 举报
回复
        private void Form1_Load(object sender, EventArgs e)
{
textBox1.MaxLength = textBox2.MaxLength = textBox3.MaxLength = textBox4.MaxLength = 10;
textBox1.TextChanged += new EventHandler(OnTextChanged);
textBox2.TextChanged += new EventHandler(OnTextChanged);
textBox3.TextChanged += new EventHandler(OnTextChanged);
textBox4.TextChanged += new EventHandler(OnTextChanged);
}

private void OnTextChanged(object sender, EventArgs e)
{
if ((sender as TextBox).Text.Length >= (sender as TextBox).MaxLength)
{
SendKeys.Send("{TAB}");
}
}
兔子-顾问 2010-10-12
  • 打赏
  • 举报
回复
textchanged事件中判断一下,4个textbox的TextChanged都注册为一个事件,例如
public void TextBoxAll_TextChanged(object sender,EventArgs e)
{
if((sender as TextBox).Text.Length > 5)//看你自己指定多少个了
{
SendKeys.Send("{TAB}");
}
}


没开vs,如果代码敲错你对照大小写啥的改改。

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧