TextBox的第一个字母 [英] First letter of the TextBox

查看:100
本文介绍了TextBox的第一个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我遇到的问题是,当用户键入Windows系列应用程序C#.NET以外的移动系列(如9、7、8等移动系列)时,我想给出一条消息.
第一个数字应该是9或7或8,我应该给这个消息.
mobile1txtTextBox的名称.
请检查并更正.

Hi to all
I am facing the problem that is I want to give a message when the user types other than the mobile series (mobile series like 9, 7, 8) windows application C#.NET.
First number should be the 9 or 7 or 8 other I should give the message.
Here mobile1txt is the TextBox name.
Please check and correct it.

private void mobile1txt_KeyPress(object sender, KeyPressEventArgs e)
{
    if (mobile1txt.Text.StartsWith("9") || mobile1txt.Text.StartsWith("8") || mobile1txt.Text.StartsWith("7"))
    {
    }
    else
    {
        MessageBox.Show("Mobile number should start with 9, 8 or 7 only", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        e.Handled = true;
        mobile1txt.Focus();
    }
}

推荐答案

按下按键时会发生KeyPress事件.这意味着mobile1txt.Text仍然为空(您可以设置一个断点并检查它).

您可以尝试KeyUp事件.
The KeyPress event happens when you press the key. It means the mobile1txt.Text is still empty (you can set a breakpoint and check it).

You can try the KeyUp event.


这篇关于TextBox的第一个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆