在Winform中如何判断用户输入多个空格?如何实现提示用户还可输入多少个字符? 如何判断用户输入多个空格?如何实现提示用户还可输入多少个字符?就想我们发帖时一样?皆在TextBox下,能不能给点具体代码?在Winform中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 javascript 获取 text.length WinForm 在 text_changed 事件里面判断 textBox.Text.Length 在TextChanged事件中实现 private void textBox1_TextChanged(object sender, EventArgs e) { this.textBox1.MaxLength = 100; //显示已经输入多少字符 this.label1.Text = this.textBox1.Text.Length / this.textBox1.MaxLength + "字"; if (textBox1.Text.Length >= 100) MessageBox.Show("已经到达" + this.textBox1.MaxLength + "字的上限~!"); } 转一个ajax实现的前台:<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick"> </asp:Timer> <asp:TextBox ID="TextBox1" runat="server" MaxLength="50"></asp:TextBox> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label" ForeColor="Red"></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel>后台:protected void Timer1_Tick(object sender, EventArgs e) { Label1.Text = "您还可以输入" + (50 - TextBox1.Text.ToString().Length) + "字"; }可以,把Label1.Text = "您还可以输入" + (50 - TextBox1.Text.ToString().Length) + "字";换成: Label1.Text = "您还可以输入" + (50 - System.Text.Encoding.Default.GetByteCount(TextBox1.Text.ToString())) + "字"; 在textbox的keypress事件里 用正则匹配\s{2,} 这样,就是有2个空格了还有多少的话,这个,太简单了textbox.text.length.自己减一下 空格数 private void textBox1_TextChanged(object sender, EventArgs e) { //空格数 int spaceLength = this.textBox.Text.Length - this.textBox.Text.replace(" ", "").Length; } 先在textBox1的属性框中设置可输入的最大字符数 private void textBox1_TextChanged(object sender, EventArgs e) { int count1 = 0;//空格数 int count2 = textBox1.MaxLength - textBox1.Text.Length;//还可输入的字符(或汉字)数 //获取输入的空格数 for (int i = 0; i < textBox1.Text.Length; i++) { if (textBox1.Text.Substring(i, 1) == " ")//注意此处必须写成" ",""中只能有一个空格 { count1++; } } MessageBox.Show("空格数为:" + count1.ToString()); MessageBox.Show("还可输入的字符(或汉字)数为:" + count2.ToString()); } textBox1.TextChanged += new EventHandler(textBox1_TextChanged); void textBox1_TextChanged(object sender, EventArgs e) { if(this.textBox1.Text.Length >100) { MessageBox.Show( "不能超过100."); } } 长度也可使用GetByteCount获取 if(this.textBox1.Text.Length >100) { MessageBox.Show( "不能超过100."); } 写了个更新程序,加密后,在xp下运行正常,在win7下只运行主程序,update程序在进程一闪而过,求大牛帮忙!~! winform中关于Button按钮的图片处理问题,请各位高手给予解答,小弟先谢谢了! 超级刺激难题 100分!!!! DataGrid1_UpdateCommand这个问题怎么解决 大家帮忙解决一下程序死掉的问题 socket基础问题!! 上传后的东西给其重命名怎样保证不重名? 关于DataSet使用的几个问题!!!!!!!!!!!! 匿名函数的编译错误 格式转换的问题,急! 关于WinForm鼠标穿透效果的几个问题 C#在控制台中的一个字符串加密问题?
{
this.textBox1.MaxLength = 100;
//显示已经输入多少字符
this.label1.Text = this.textBox1.Text.Length / this.textBox1.MaxLength + "字";
if (textBox1.Text.Length >= 100)
MessageBox.Show("已经到达" + this.textBox1.MaxLength + "字的上限~!");
}
转一个ajax实现的
前台:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick">
</asp:Timer>
<asp:TextBox ID="TextBox1" runat="server" MaxLength="50"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label" ForeColor="Red"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>后台:
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = "您还可以输入" + (50 - TextBox1.Text.ToString().Length) + "字";
}
可以,把Label1.Text = "您还可以输入" + (50 - TextBox1.Text.ToString().Length) + "字";
换成:
Label1.Text = "您还可以输入" + (50 - System.Text.Encoding.Default.GetByteCount(TextBox1.Text.ToString())) + "字";
\s{2,} 这样,就是有2个空格了
还有多少的话,这个,太简单了
textbox.text.length.
自己减一下
private void textBox1_TextChanged(object sender, EventArgs e)
{
//空格数
int spaceLength = this.textBox.Text.Length - this.textBox.Text.replace(" ", "").Length; }
private void textBox1_TextChanged(object sender, EventArgs e)
{
int count1 = 0;//空格数
int count2 = textBox1.MaxLength - textBox1.Text.Length;//还可输入的字符(或汉字)数
//获取输入的空格数
for (int i = 0; i < textBox1.Text.Length; i++)
{
if (textBox1.Text.Substring(i, 1) == " ")//注意此处必须写成" ",""中只能有一个空格
{
count1++;
}
}
MessageBox.Show("空格数为:" + count1.ToString());
MessageBox.Show("还可输入的字符(或汉字)数为:" + count2.ToString());
}
void textBox1_TextChanged(object sender, EventArgs e)
{
if(this.textBox1.Text.Length >100)
{
MessageBox.Show( "不能超过100.");
}
} 长度也可使用GetByteCount获取
{
MessageBox.Show( "不能超过100.");
}